Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HTTP API Design for iOS Applications

HTTP API Design for iOS Applications


Patrick Van Stee

August 16, 2013

More Decks by Patrick Van Stee

Other Decks in Programming


  1. HTTP API Design for iOS Applications

  2. @vanstee Big Nerd Ranch

  3. • Modeling Resources • Tools: Server and Client • Real

    world problems • Future
  4. Modeling Resources

  5. The key abstraction of information in REST is a resource.

  6. 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.
  7. Resources are not just database records

  8. Resources are the nouns. HTTP methods are the verbs. URIs

    are the identifiers. Media types are the representations.
  9. But what about transactions? searches? complex actions?

  10. Don’t do this: POST /accounts/1/transfer/500.00/to/2 Try this instead: POST /transactions

    { “from”: 1, “to”: 2, “amount”: 500.00 }
  11. Tools

  12. Server-side • Rails • Active Model Serializers • Custom Responders

    • rack-test and json_spec
  13. Client-side • AFNetworking • RestKit (if you really need it)

    • VCRURLConnection and mitmproxy
  14. Real World Problems

  15. Versioning Don’t do this: POST /v1/users/1 Try this instead: POST

    /users/1 Accept: application/json; version=1.0
  16. Authentication • OAuth2 with API routes for token generation •

    NSURLConnection supports cookies • Basic Authentication over HTTPS*
  17. Caching • NSURLCache has support for Cache-Control and ETags •

    AFNetworking supports this by default • Rails gives you these for free
  18. Smarter Requests • Side loading associated resources • HTTP Pipelining

    for GET, HEAD, PUT, and DELETE requests • HTTP compression
  19. Future

  20. HTTP 2.0 • Based on SPDY • Multiplexing • Server

    Push • Better compression
  21. JSON API • Standard hypermedia type • Always namespaced •

    Always returns collections for easy parsing • Support for batch operations
  22. JSON Patch • Standard hypermedia type for updating records •

    Easily handle associations • Send minimal amount of information
  23. Thanks blog.steveklabnik.com designinghypermediaapis.com afnetworking.com jsonapi.org