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

Content Negotiation for REST APIs

Erik Berlin
October 22, 2014

Content Negotiation for REST APIs

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

Erik Berlin

October 22, 2014
Tweet

More Decks by Erik Berlin

Other Decks in Technology

Transcript

  1. Content Negotiation
    for REST APIs

    View full-size slide

  2. SOAP vs. REST

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  10. FILE NAME
    EXTENSIONS

    View full-size slide

  11. RESOURCE VS.
    REPRESENTATION

    View full-size slide

  12. XML REPRESENTATION
    GET /users/sferik.xml



    sferik

    Erik


    View full-size slide

  13. JSON REPRESENTATION
    GET /users/sferik.json


    {

    “id”: “sferik”,

    “name”: “Erik”

    }

    View full-size slide

  14. RESOURCE VS.
    REPRESENTATION
    GET /users/sferik.xml
    GET /users/sferik.json

    View full-size slide

  15. RESOURCE VS.
    REPRESENTATION
    GET /users/sferik

    View full-size slide

  16. ACCEPT HEADER
    The Accept request-header field can be used to
    specify certain media types which are acceptable
    for the response.

    View full-size slide

  17. ACCEPT HEADER
    GET /avatars/sferik.png


    Accept: image/png

    View full-size slide

  18. 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

    View full-size slide

  19. ACCEPT HEADER
    GET /avatars/sferik


    Accept: video/*,

    image/gif; q=0.8,

    image/*; q=0.5,

    application/json; q=0.1

    View full-size slide

  20. 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.

    View full-size slide

  21. ACCEPT-LANGUAGE
    HEADER
    GET /index.se.html


    Accept-Language: se

    View full-size slide

  22. ACCEPT-LANGUAGE
    HEADER
    GET /index


    Accept-Language: se,

    en-us;q=0.8,

    en;q=0.7

    View full-size slide

  23. FORMATS CHANGE

    View full-size slide

  24. 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.

    View full-size slide

  25. EXPOSE RESOURCES,

    NOT REPRESENTATIONS

    View full-size slide