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
HTTP API & Python
Search
Milan Cermak
February 20, 2013
Programming
3
230
HTTP API & Python
Slides from my talk at Brno and Prague Python user group meetups on HTTP/REST APIs.
Milan Cermak
February 20, 2013
Tweet
Share
More Decks by Milan Cermak
See All by Milan Cermak
Building a CI/CD pipeline on AWS
milancermak
0
5k
Designing mobile friendly APIs
milancermak
0
100
Programování pro iOS z pohledu pythonistu
milancermak
0
230
Prečo povedať nie SQL
milancermak
1
110
Other Decks in Programming
See All in Programming
Piniaの現状と今後
waka292
5
1.5k
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
160
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
270
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
620
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.6k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
310
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
24
11k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
280
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
260
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
250
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
450
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
95
5.2k
Building Adaptive Systems
keathley
38
2.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
32
1.8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Building Your Own Lightsaber
phodgson
102
6.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
GraphQLとの向き合い方2022年版
quramy
43
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
How GitHub (no longer) Works
holman
311
140k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
4
380
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Transcript
HTTP API & Py Milan Čermák Pyvo Praha, 20. 2.
2013 Wednesday, February 20, 13
What makes a good API? Wednesday, February 20, 13
Wednesday, February 20, 13
Consistency Wednesday, February 20, 13
Consistency Predictability Wednesday, February 20, 13
Consistency Predictability Adherence to standards Wednesday, February 20, 13
Consistency Predictability Adherence to standards Great documentation Wednesday, February 20,
13
Why HTTP? Wednesday, February 20, 13
"While HTTP isn’t always the best answer, it’s a damn
fine first guess." Coda Hale Wednesday, February 20, 13
Benefits of HTTP Wednesday, February 20, 13
Benefits of HTTP The most widespread application protocol Wednesday, February
20, 13
Benefits of HTTP The most widespread application protocol Statelessness Wednesday,
February 20, 13
Benefits of HTTP The most widespread application protocol Statelessness Optional
caching Wednesday, February 20, 13
Benefits of HTTP The most widespread application protocol Statelessness Optional
caching Promotes layered infrastructure Wednesday, February 20, 13
Benefits of HTTP The most widespread application protocol Statelessness Optional
caching Promotes layered infrastructure etc. Wednesday, February 20, 13
Limitations of HTTP Wednesday, February 20, 13
Limitations of HTTP Authorization Wednesday, February 20, 13
Limitations of HTTP Authorization Statelessness Wednesday, February 20, 13
Limitations of HTTP Authorization Statelessness Verbosity Wednesday, February 20, 13
Limitations of HTTP Authorization Statelessness Verbosity Crippled parallelism Wednesday, February
20, 13
"REST" if protocol.startswith("http") else "you're doing it wrong" Wednesday, February
20, 13
Set of architectural constraints Wednesday, February 20, 13
Set of architectural constraints Client-server Wednesday, February 20, 13
Set of architectural constraints Client-server Stateless Wednesday, February 20, 13
Set of architectural constraints Client-server Stateless Cacheable Wednesday, February 20,
13
Set of architectural constraints Client-server Stateless Cacheable Layered Wednesday, February
20, 13
Set of architectural constraints Client-server Stateless Cacheable Layered Uniform interface
* Wednesday, February 20, 13
How can Python help? Wednesday, February 20, 13
OOP Wednesday, February 20, 13
OOP URI ~ Class handler mapping Wednesday, February 20, 13
import handlers urls = [(r"/user", handlers.users.NewUser), (r"/user/(\d+)", handlers.users.User)] class User(handler.base.BaseHandler):
def delete(self, user_id): pass def get(self, user_id): pass def post(self, user_id): pass Wednesday, February 20, 13
class UserValidatorMixin(object): def check_user_data(self, user_dict): pass class User(handler.base.BaseHandler, UserValidatorMixin): def
post(self, user_id): new_user = self.get_argument(“user”) if not self.check_user_data(new_user): return self.http_error(400, “Invalid data”) Wednesday, February 20, 13
Middleware Wednesday, February 20, 13
Wednesday, February 20, 13
Extending JSONEncoder Wednesday, February 20, 13
import json class AppJSONEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, User):
return {"name": obj.name, "height": obj.height, "cash": obj.get_bank_account_balance()} return json.JSONEncoder.default(self, obj) user = User("1337") json.dumps(user, cls=AppJSONEncoder) Wednesday, February 20, 13
What about mobile? Wednesday, February 20, 13
Compression of HTTP bodies GET /user/1337 HTTP/1.1 Host: api.napyvo.io Accept-Encoding:
gzip, identity Wednesday, February 20, 13
Compression of HTTP bodies HTTP/1.1 200 OK Content-Encoding: gzip Content-Type:
application/json; charset=utf-8 Wednesday, February 20, 13
Compression of HTTP bodies POST /user HTTP/1.1 Host: api.napyvo.io Content-Encoding:
gzip Content-Type: application/json [gzipped representation of a user] Wednesday, February 20, 13
Caching Cache-Control: max-age=3600 Expires: Thu, 31 Jan 2013 22:00:00 GMT
<- Last-Modified: Thu, 31 Jan 2013 18:30:00 GMT -> If-Modified-Since: Wed, 30 Jan 2013 13:37:00 GMT ETag: foo If-None-Match: foo Wednesday, February 20, 13
Partial resources Wednesday, February 20, 13
GET /car/9 {"car": { "color": "red", "passengers": [ {"href": "/user/1337",
"rel": "self"}] } } Wednesday, February 20, 13
GET /car/9?zoom=passengers {"car": { "color": "red", "passengers": [ {"href": "/user/1337",
"rel": "self", "name": "Milan", "drink": "beer", "skills": ["python", "http"], }] } } Wednesday, February 20, 13
The promise of Hypermedia Wednesday, February 20, 13
Hypermedia as the engine of application state Wednesday, February 20,
13
Q & A Wednesday, February 20, 13