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
460
ReST APIs @ PyCon India, 2015
Devi
October 03, 2015
Tweet
Share
More Decks by Devi
See All by Devi
Understanding ElasticSearch
asldevi
0
94
Logging the right way!
asldevi
2
290
Growing with communities
asldevi
0
73
Observability at scale
asldevi
0
170
We shall overcome - gender gap in tech
asldevi
1
430
How to kickstart your (technical) career
asldevi
0
55
Testing micro-services made easy @ PyCon 2018
asldevi
1
300
Growing with ElasticSearch
asldevi
0
93
Web development - Code to Deployment
asldevi
1
630
Other Decks in Technology
See All in Technology
Gradle Build Scanを使ってビルドのことを知ろう potatotips #87
tomorrowkey
2
160
Tellus の衛星データを見てみよう #mf_fukuoka
kongmingstrap
0
270
いいたいことちゃんという
tkengo
0
230
Microsoft for Startups Founders Hub_20240429 update
daikikanemitsu
1
2.4k
競技としてのKaggle、役に立つKaggle
yu4u
6
2.3k
今さら聞けないDocker入門 〜 Dockerfileのベストプラクティス編
devops_vtj
4
540
.NET Profiler in 2024.
kkamegawa
2
1.4k
AOAI をきっかけに 社内の Azure 管理を見直した話
recruitengineers
PRO
1
450
認知症フレンドリーテックとスタックチャン
naokiuc
0
250
アクセス制御にまつわる改善 / Improving access control
itkq
0
590
データベース02: データベースの概念
trycycle
0
180
リテール金融(キャッシュレス・ネット銀行・ネット証券)の競争環境と経済圏
8maki
0
1.6k
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
34
8.9k
Fireside Chat
paigeccino
22
2.6k
The Brand Is Dead. Long Live the Brand.
mthomps
49
29k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
245
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
33
6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
242
1.2M
Automating Front-end Workflow
addyosmani
1357
200k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Web development in the modern age
philhawksworth
203
10k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
188
16k
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