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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Devi
October 03, 2015
Technology
1
590
ReST APIs @ PyCon India, 2015
Devi
October 03, 2015
Tweet
Share
More Decks by Devi
See All by Devi
Understanding ElasticSearch
asldevi
0
100
Logging the right way!
asldevi
2
310
Growing with communities
asldevi
0
89
Observability at scale
asldevi
0
200
We shall overcome - gender gap in tech
asldevi
1
460
How to kickstart your (technical) career
asldevi
0
75
Testing micro-services made easy @ PyCon 2018
asldevi
1
430
Growing with ElasticSearch
asldevi
0
100
Web development - Code to Deployment
asldevi
1
690
Other Decks in Technology
See All in Technology
会社紹介資料 / Sansan Company Profile
sansan33
PRO
15
400k
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
150
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
470
Context Engineeringの取り組み
nutslove
0
380
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.6k
コンテナセキュリティの最新事情 ~ 2026年版 ~
kyohmizu
5
920
Webhook best practices for rock solid and resilient deployments
glaforge
2
300
日本の85%が使う公共SaaSは、どう育ったのか
taketakekaho
1
240
pool.ntp.orgに ⾃宅サーバーで 参加してみたら...
tanyorg
0
320
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
210
usermode linux without MMU - fosdem2026 kernel devroom
thehajime
0
240
配列に見る bash と zsh の違い
kazzpapa3
3
160
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
530
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Context Engineering - Making Every Token Count
addyosmani
9
670
Exploring anti-patterns in Rails
aemeredith
2
250
The Invisible Side of Design
smashingmag
302
51k
It's Worth the Effort
3n
188
29k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
260
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Google's AI Overviews - The New Search
badams
0
910
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Believing is Seeing
oripsolob
1
58
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