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
Tweet

More Decks by Patrick Van Stee

Other Decks in Programming

Transcript

  1. HTTP API
    Design
    for iOS Applications

    View Slide

  2. @vanstee
    Big Nerd Ranch

    View Slide

  3. • Modeling Resources
    • Tools: Server and Client
    • Real world problems
    • Future

    View Slide

  4. Modeling
    Resources

    View Slide

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

    View Slide

  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.

    View Slide

  7. Resources are not
    just database records

    View Slide

  8. Resources are the nouns.
    HTTP methods are the verbs.
    URIs are the identifiers.
    Media types are the representations.

    View Slide

  9. But what about transactions?
    searches?
    complex actions?

    View Slide

  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 }

    View Slide

  11. Tools

    View Slide

  12. Server-side
    • Rails
    • Active Model Serializers
    • Custom Responders
    • rack-test and json_spec

    View Slide

  13. Client-side
    • AFNetworking
    • RestKit (if you really need it)
    • VCRURLConnection and
    mitmproxy

    View Slide

  14. Real
    World
    Problems

    View Slide

  15. Versioning
    Don’t do this:
    POST /v1/users/1
    Try this instead:
    POST /users/1
    Accept: application/json; version=1.0

    View Slide

  16. Authentication
    • OAuth2 with API routes for token
    generation
    • NSURLConnection supports
    cookies
    • Basic Authentication over HTTPS*

    View Slide

  17. Caching
    • NSURLCache has support for
    Cache-Control and ETags
    • AFNetworking supports this by
    default
    • Rails gives you these for free

    View Slide

  18. Smarter Requests
    • Side loading associated
    resources
    • HTTP Pipelining for GET, HEAD,
    PUT, and DELETE requests
    • HTTP compression

    View Slide

  19. Future

    View Slide

  20. HTTP 2.0
    • Based on SPDY
    • Multiplexing
    • Server Push
    • Better compression

    View Slide

  21. JSON API
    • Standard hypermedia type
    • Always namespaced
    • Always returns collections for
    easy parsing
    • Support for batch operations

    View Slide

  22. JSON Patch
    • Standard hypermedia type for
    updating records
    • Easily handle associations
    • Send minimal amount of
    information

    View Slide

  23. Thanks
    blog.steveklabnik.com
    designinghypermediaapis.com
    afnetworking.com
    jsonapi.org

    View Slide