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

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

Kyle Fuller

March 22, 2015
Tweet

More Decks by Kyle Fuller

Other Decks in Technology

Transcript

  1. 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>
  2. 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>
  3. 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)
  4. with hypermedia 4 We’re offered to create a question 4

    Fill in the form it gives you 4 Submit the form
  5. Siren Link { "entities": [ { "links" { { "rel":

    ["self"], "href": "/questions/1/choices/1" } }, "rel": ["choices"], "properties": {"choice": "Swift", "votes": 22} } ] }
  6. Siren Link { "entities": [ { "rel": ["choices"], "properties": {"choice":

    "Swift", "votes": 22}, "actions": [ { "href": "/questions/1/choices/1", "name": "vote", "method": "POST" } ] } ] }
  7. Siren Action { "actions": { "create": { "href": "/questions", "method":

    "POST", "fields": [ { "name": "question" }, { "name": "choices" } ] } } }
  8. Siren Action { "actions": { "create": { "href": "/questions", "method":

    "POST", "fields": [ { "name": "question" }, { "name": "choices" } ], "type": "application/x-www-form-urlencoded" } } }
  9. Siren Action { "actions": { "create": { "href": "/questions", "method":

    "POST", "fields": [ { "name": "question" }, { "name": "choices" } ], "type": "application/json" } } }
  10. { "actions": { "create": { "href": "/questions", "method": "POST", "fields":

    [ { "name": "question" }, { "name": "choices" } ], "type": "application/json" } } }
  11. Ability to change implementation details 4 Change URIs of resources

    (/polls/{id} -> / questions/{slug}) 4 Change HTTP methods (PUT -> PATCH)
  12. 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
  13. 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
  14. Using a transition if let transition = representor.transitions["create"] { }

    else { // Gracefully handle the lack of this transition }
  15. 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