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 full-size slide

  2. @vanstee
    Big Nerd Ranch

    View full-size slide

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

    View full-size slide

  4. Modeling
    Resources

    View full-size slide

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

    View full-size 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 full-size slide

  7. Resources are not
    just database records

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  13. Real
    World
    Problems

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide