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
5.1k
Designing mobile friendly APIs
milancermak
0
100
Programování pro iOS z pohledu pythonistu
milancermak
0
230
Prečo povedať nie SQL
milancermak
1
120
Other Decks in Programming
See All in Programming
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
470
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
快速入門可觀測性
blueswen
0
350
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
CSC305 Lecture 26
javiergs
PRO
0
140
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
3
370
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
Featured
See All Featured
Building an army of robots
kneath
302
44k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Building Applications with DynamoDB
mza
91
6.1k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Documentation Writing (for coders)
carmenintech
66
4.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
The Invisible Side of Design
smashingmag
298
50k
Code Reviewing Like a Champion
maltzj
520
39k
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