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

Content Negotiation for REST APIs

1f74b13f1e5c6c69cb5d7fbaabb1e2cb?s=47 Erik Berlin
October 22, 2014

Content Negotiation for REST APIs

Closing keynote at the Nordic APIs Platform Summit in Stockholm, Sweden.

1f74b13f1e5c6c69cb5d7fbaabb1e2cb?s=128

Erik Berlin

October 22, 2014
Tweet

Transcript

  1. Content Negotiation for REST APIs

  2. 
 @sferik

  3. None
  4. None
  5. None
  6. SOAP vs. REST

  7. SOAP vs. REST SOAP POST /api.xml

  8. SOAP vs. REST SOAP POST /api.xml

  9. SOAP vs. REST SOAP POST /api.xml

  10. SOAP vs. REST SOAP POST /api.xml REST GET /users/sferik.json

  11. SOAP vs. REST SOAP POST /api.xml REST GET /users/sferik.json

  12. SOAP vs. REST SOAP POST /api.xml REST GET /users/sferik.json

  13. SOAP vs. REST SOAP POST /api.xml REST GET /users/sferik.json

  14. FILE NAME EXTENSIONS

  15. None
  16. RESOURCE VS. REPRESENTATION

  17. XML REPRESENTATION GET /users/sferik.xml
 
 <user>
 <id>sferik</id>
 <name>Erik</name>
 </user>

  18. JSON REPRESENTATION GET /users/sferik.json
 
 {
 “id”: “sferik”,
 “name”: “Erik”


    }
  19. RESOURCE VS. REPRESENTATION GET /users/sferik.xml GET /users/sferik.json

  20. RESOURCE VS. REPRESENTATION GET /users/sferik

  21. ACCEPT HEADER The Accept request-header field can be used to

    specify certain media types which are acceptable for the response.
  22. ACCEPT HEADER GET /avatars/sferik.png
 
 Accept: image/png

  23. ACCEPT HEADER GET /avatars/sferik
 
 Accept: image/png,
 image/jpeg; q=0.8,
 image/gif;

    q=0.8,
 image/*; q=0.5,
 application/json; q=0.1
  24. ACCEPT HEADER GET /avatars/sferik
 
 Accept: video/*,
 image/gif; q=0.8,
 image/*;

    q=0.5,
 application/json; q=0.1
  25. ACCEPT-LANGUAGE HEADER The Accept-Language request-header field is similar to Accept,

    but restricts the set of natural languages that are preferred as a response to the request.
  26. ACCEPT-LANGUAGE HEADER GET /index.se.html
 
 Accept-Language: se

  27. ACCEPT-LANGUAGE HEADER GET /index
 
 Accept-Language: se,
 en-us;q=0.8,
 en;q=0.7

  28. None
  29. None
  30. None
  31. None
  32. None
  33. FORMATS CHANGE

  34. FIELDING ON REST REST is software design on the scale

    of decades: every detail is intended to promote software longevity and independent evolution. Many of the constraints are directly opposed to short-term efficiency. Unfortunately, people are fairly good at short-term design, and usually awful at long- term design. Most don’t think they need to design past the current release.
  35. EXPOSE RESOURCES,
 NOT REPRESENTATIONS

  36. TACK