Embracing Change with REST

Embracing Change with REST

People are fairly good at short-term design, and usually awful at long-term design". Let's learn how we can promote longevity and independent evolution of your API by decoupling and encapsulation using the engine of application state in REST.

Resources to learn more:

- Solving Fizz Buzz with Hypermedia: http://smizell.com/weblog/2014/solving-fizzbuzz-with-hypermedia
- REST APIs must be hypertext driven - http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
- Representor in Swift - https://github.com/the-hypermedia-project/representor-swift
- Roy Fielding on Versioning - http://www.infoq.com/articles/roy-fielding-on-versioning
- Polls API - Implementation of a RESTful API - https://github.com/apiaryio/polls-api
- rivr-rest: Python framework for building RESTful APIs - http://github.com/rivrproject/rivr-rest

D200a17dd269fd4001bacb11662dab4b?s=128

Kyle Fuller

March 22, 2015
Tweet

Transcript

  1. 7.
  2. 8.
  3. 11.
  4. 20.
  5. 25.
  6. 26.
  7. 28.
  8. 33.

    GET http://polls.com/ <html> <body> <h1>Things you can do</h1> <ul> <li><a

    href="/questions/new" rel="create">Make a new question</a></li> </ul> </body> </html>
  9. 34.

    GET http://polls.com/ <html> <body> <h1>Things you can do</h1> <ul> <li><a

    href="/polls/new" rel="create">Make a new question</a></li> </ul> </body> </html>
  10. 35.

    Creating a question the bad way 4 Construct a 'new

    question' URL 4 Submit a form given our pre-existing knowledge of how it may look 4 Visit the page (it may or may not work)
  11. 36.

    with hypermedia 4 We’re offered to create a question 4

    Fill in the form it gives you 4 Submit the form
  12. 39.
  13. 47.

    Siren Link { "entities": [ { "links" { { "rel":

    ["self"], "href": "/questions/1/choices/1" } }, "rel": ["choices"], "properties": {"choice": "Swift", "votes": 22} } ] }
  14. 48.

    Siren Link { "entities": [ { "rel": ["choices"], "properties": {"choice":

    "Swift", "votes": 22}, "actions": [ { "href": "/questions/1/choices/1", "name": "vote", "method": "POST" } ] } ] }
  15. 49.

    Siren Action { "actions": { "create": { "href": "/questions", "method":

    "POST", "fields": [ { "name": "question" }, { "name": "choices" } ] } } }
  16. 50.

    Siren Action { "actions": { "create": { "href": "/questions", "method":

    "POST", "fields": [ { "name": "question" }, { "name": "choices" } ], "type": "application/x-www-form-urlencoded" } } }
  17. 51.

    Siren Action { "actions": { "create": { "href": "/questions", "method":

    "POST", "fields": [ { "name": "question" }, { "name": "choices" } ], "type": "application/json" } } }
  18. 52.

    { "actions": { "create": { "href": "/questions", "method": "POST", "fields":

    [ { "name": "question" }, { "name": "choices" } ], "type": "application/json" } } }
  19. 55.

    Ability to change implementation details 4 Change URIs of resources

    (/polls/{id} -> / questions/{slug}) 4 Change HTTP methods (PUT -> PATCH)
  20. 56.

    Ability to change implementation details 4 Change URIs of resources

    (/polls/{id} -> / questions/{slug}) 4 Change HTTP methods (PUT -> PATCH) 4 Change the content-type
  21. 57.

    Ability to change implementation details 4 Change URIs of resources

    (/polls/{id} -> / questions/{slug}) 4 Change HTTP methods (PUT -> PATCH) 4 Change the content-type 4 Change fields used in forms
  22. 60.
  23. 63.

    Using a transition if let transition = representor.transitions["create"] { }

    else { // Gracefully handle the lack of this transition }
  24. 67.
  25. 68.

    Resources 4 REST APIs must be hypertext driven 4 Representor

    4 Roy Fielding on Versioning 4 Polls API 4 rivr rest 4 Solving Fizz Buzz with Hypermedia