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

Designing mobile friendly APIs

Designing mobile friendly APIs

Slides from the talk I gave at 1st HTTP API group meetup in Berlin.

5f27d0b43fc28785db65c57ae7e81ec5?s=128

Milan Cermak

February 13, 2014
Tweet

Transcript

  1. Mobile friendly APIs Milan Cermak HTTP API Meetup Group Berlin

    Feb 13, 2014
  2. General rules

  3. be religious about documentation

  4. when in doubt RFC 2616

  5. Designing for mobile

  6. Optimize for size and speed

  7. • Bytes matter • Power consumption: • 3G > wifi

    > 2G • On cellular, only 2 concurrent networking requests
  8. Content-Encoding: gzip

  9. ETag If-Match If-None-Match

  10. Make the API flexible

  11. Make the API flexible • fields parameter

  12. GET /people/1! {“id”: 1,! “name”: “Milan Cermak”,! “age”: 27,! “hobbies”:

    [“programming”, “ice cream”],! ...! }
  13. GET /people/1?fields=name,age! {“name”: “Milan Cermak”,! “age”: 27}

  14. Minimal vs. full approach ! • Send only the minimal

    possible representation, let the users specify what they want via fields! • Send the full available representation of the resource
  15. Make the API flexible • zoom parameter

  16. GET /hobbies/programming! {“people”: [“1”, “2”, “3”, “5”, “8”, “11”],! “popularity”:

    0.75,! ...! }
  17. GET /hobbies/programming?zoom=people! {“people”: [! {“id”: 1,! “name”: “Milan Cermak”,! “age”:

    27! ...! },! ...]! }
  18. Batched requests

  19. Batched requests • i.e. Facebook Graph API • A solution

    until widespread adoption of HTTP2 • Not really RESTful, but really useful
  20. POST /api/batch! {[! {“method”: “GET”! “relative_url”: “people/1”! },! {“method”: “GET”,!

    “relative_url”: “hobbies/dogs”! }! ]}
  21. Batched requests • Server-side implementation can be tricky: • Error

    handling • HTTP headers • Parallel execution vs. POST/PUT/DELETE
  22. Thank you