Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ReST APIs @ PyCon India, 2015
Search
Devi
October 03, 2015
Technology
1
530
ReST APIs @ PyCon India, 2015
Devi
October 03, 2015
Tweet
Share
More Decks by Devi
See All by Devi
Understanding ElasticSearch
asldevi
0
98
Logging the right way!
asldevi
2
300
Growing with communities
asldevi
0
87
Observability at scale
asldevi
0
190
We shall overcome - gender gap in tech
asldevi
1
450
How to kickstart your (technical) career
asldevi
0
58
Testing micro-services made easy @ PyCon 2018
asldevi
1
360
Growing with ElasticSearch
asldevi
0
98
Web development - Code to Deployment
asldevi
1
650
Other Decks in Technology
See All in Technology
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
200
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
270
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
490
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
ハイテク休憩
sat
PRO
2
170
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
270
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
290
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
生成AIのガバナンスの全体像と現実解
fnifni
1
190
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Become a Pro
speakerdeck
PRO
26
5k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Building Your Own Lightsaber
phodgson
103
6.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Why Our Code Smells
bkeepers
PRO
335
57k
Transcript
ReST APIs What, Why and How? A. S. L. Devi
PyCon India, 2015
What is an API programmable interface (to web services) Specifies
the request and response formats for the communication between a client and a server.
Why? • Public APIs - services through API - glues
best of several languages / technologies - AWS, Stripe, ElasticSearch, Twitter, GrapheneDB etc • Private APIs - same service offered in different UIs - a mobile app, a web app, desktop app - Slack, FaceBook etc
• Resources • URLs (Uniform Resource Locators) • HTTP -
methods and response codes ReST - Representational State Transfer
Each resource is identified by a URL. /customers /customers/5 /customers/5/orders
/customers/5/orders/42 /customers/5/orders?completed=true /customers/5/orders?completed=true&page=1 ReST - Resources
ReST - HTTP Verbs • GET - Retrieve a resource
• POST - Create a resource • PUT - Create/update a resource • DELETE - Delete a resource GET, PUT and DELETE are idempotent.
• simple • consistent across - one way of doing
things • backward compatible • HATEOS - linked documents • Well documented :) How should a ReST API be?
* taken from “Building Web APIs with Flask” with thanks
to Miguel Grinberg
$ curl -XGET http://api.x.com/v1/customers HTTP/1.1 200 OK Content-Type: application/json {
"customers": [] } $ curl -XGET http://api.x.com/v1/customers/1 { “name”: “Alice”, “links”: { “orders”: http://api.x.com/customers/1/orders “self”: http://api.x.com/customers/1 }} CRUD: Create Read Update Delete $ curl -XPOST http://api.x.com/v1/customers - d “name=Alice” HTTP/1.1 201 CREATED Content-Type: application/json Location: http://api.x.com/ customers/1 {} $ curl -XPUT http://api.x.com/v1/customers/1 -d “name=Bob” HTTP/1.1 200 OK $ http DELETE http://api.x.com/customers/1 HTTP/1.1 204 No Content
HATEOS - Linked documents $ curl -XGET http://api.x.com/v1/customers/1 { “name”:
“Alice”, “links”: { “self”: “http://api.x.com/v1/customers/1, “orders”: “http://api.x.com/v1/customers/1/orders”, } }
More HATEOS $ curl -XGET http://api.x.com/v1/customers/1/orders/10 { “links”: { “self”:
“http://api.x.com/v1/orders/10”, “customer”: “http://api.x.com/v1/customers/1” }, “orders”: [{ “date”: 2015-01-01-00:00:09Z, “items”: [ {“quantity”: 2, “product”: “XXX-1”}, {“quantity”: 3, “product”: “XYY-42”}, ] ]} }
How to choose a library to build ReST API •
Data validation • Authentication & Authorization • Not tightly coupled with ORM or database • Pagination, rate limits, filters etc.
Authentication & Authorization - no assumptions of the client side
- global authentication - Authorization header - Basic Authentication - Token-Based - HMAC based
• http://restful-api-design.readthedocs.org/en/latest/ • http://restcookbook.com/ • http://player.oreilly.com/videos/9781491911938 • http://jsonapi.org References
Questions
Thank You ! @asldevi