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
118
4.9k
vanstee
3
550
vanstee
8
500
vanstee
22
1.8k
vanstee
4
360
vanstee
1
120
vanstee
4
260
vanstee
10
480
Other Decks in Programming
See All in Programming
shun_oshidari
6
2.9k
rockname
1
330
palkan
2
350
sgeengineer
1
190
kaz29
2
130
tooppoo
1
460
ktgrstsh
0
160
mrtc0
1
140
takuyaa
4
480
fr0gger
2
2.8k
n1215
1
470
nori0__
1
490
Featured
See All Featured
zakiwarfel
88
3.4k
carmenhchung
34
1.6k
nonsquared
81
3.4k
mojombo
359
62k
chriscoyier
498
130k
yeseniaperezcruz
302
31k
lemiorhan
628
47k
robhawkes
53
2.9k
jeffersonlam
330
15k
denniskardys
220
120k
62gerente
586
200k
maggiecrowley
10
550
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