Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
HTTP API Design for iOS Applications
Patrick Van Stee
August 16, 2013
Programming
11
350
HTTP API Design for iOS Applications
Patrick Van Stee
August 16, 2013
Tweet
Share
More Decks by Patrick Van Stee
See All by Patrick Van Stee
vanstee
116
4.8k
vanstee
3
540
vanstee
8
500
vanstee
22
1.8k
vanstee
4
360
vanstee
1
120
vanstee
4
260
vanstee
10
470
Other Decks in Programming
See All in Programming
freekmurze
0
210
line_developers_tw2
0
690
kyoheig3
0
420
nbkouhou
0
890
aratayokoyama
0
200
ufoo68
1
170
siketyan
1
110
line_developers_tw
0
530
taoshotaro
1
360
itosho525
0
360
dictoss
0
170
line_developers_tw
1
480
Featured
See All Featured
addyosmani
1348
190k
morganepeng
17
1.1k
holman
288
130k
andyhume
62
3.4k
hursman
106
9.2k
lauravandoore
11
1.3k
destraynor
146
19k
thoeni
4
550
dougneiner
55
5.4k
chriscoyier
145
19k
bkeepers
52
4.1k
imathis
478
150k
Transcript
HTTP API Design for iOS Applications
@vanstee Big Nerd Ranch
• Modeling Resources • Tools: Server and Client • Real
world problems • Future
Modeling Resources
The key abstraction of information in REST is a resource.
re·source /ˈrēˌsôrs/ A resource is a conceptual mapping to a
set of entities, not the entity that corresponds to the mapping at any particular point in time.
Resources are not just database records
Resources are the nouns. HTTP methods are the verbs. URIs
are the identifiers. Media types are the representations.
But what about transactions? searches? complex actions?
Don’t do this: POST /accounts/1/transfer/500.00/to/2 Try this instead: POST /transactions
{ “from”: 1, “to”: 2, “amount”: 500.00 }
Tools
Server-side • Rails • Active Model Serializers • Custom Responders
• rack-test and json_spec
Client-side • AFNetworking • RestKit (if you really need it)
• VCRURLConnection and mitmproxy
Real World Problems
Versioning Don’t do this: POST /v1/users/1 Try this instead: POST
/users/1 Accept: application/json; version=1.0
Authentication • OAuth2 with API routes for token generation •
NSURLConnection supports cookies • Basic Authentication over HTTPS*
Caching • NSURLCache has support for Cache-Control and ETags •
AFNetworking supports this by default • Rails gives you these for free
Smarter Requests • Side loading associated resources • HTTP Pipelining
for GET, HEAD, PUT, and DELETE requests • HTTP compression
Future
HTTP 2.0 • Based on SPDY • Multiplexing • Server
Push • Better compression
JSON API • Standard hypermedia type • Always namespaced •
Always returns collections for easy parsing • Support for batch operations
JSON Patch • Standard hypermedia type for updating records •
Easily handle associations • Send minimal amount of information
Thanks blog.steveklabnik.com designinghypermediaapis.com afnetworking.com jsonapi.org