Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Links, forms and unicorns

3,012 views

Published on

Published in: Technology, Education
  • accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ...................................ALL FOR EBOOKS................................................. Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Entertaining and full of awesome!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Links, forms and unicorns

  1. 1. @serialseb seb@serialseb.com http://codebetter.com/sebastienlambla/Architect, trainer, speaker, developer, mayhem inducer…
  2. 2. by the people, for the people
  3. 3. Web Development Done Right
  4. 4. Building Hypermedia APIsWhy links and forms will make your ReSTful API better
  5. 5. Links, forms and unicornsBuilding Hypermedia APIsWhy links and forms will make your ReSTful API better
  6. 6. Your mission should you accept it…• Go to Paris, give the agent your name and ask for his favourite monument• Go to Brussels, tell the agent what you learnt, ask for their favourite food• Go to Copenhagen, tell them what you learnt, ask for their favourite painter• In Malmo, tell them what you learnt, receive the secret message
  7. 7. Your mission should you accept it…• POST to /paris, expect {“status”: “ok”, “monument”: ??}• POST to /brussels with {“monument”: ??}, expect {“status”: “ok”, “food”: ??}• POST to /copenhagen with {“food”: ??}, expect {“status”:”ok”, “artist”: ??}• POST to /malmo with {“artist”: ??}, expect {“status”: “ok”, “secret”: ??}
  8. 8. public void travel() { var response = _client .Post(“/paris”, new{name=“Pixie”}) .Send(); if (response.body.status == “ok”) { response = _client.Post(“/brussels”, new { monument=response.body.monument }).Send(); // etc }}
  9. 9. > POST /paris> {“name”: “resty galore”}
  10. 10. Oh no!The French don’t speak English! (who knew!)
  11. 11. > POST /paris> {“name”: “resty galore”}< 200 OK< {“status”: “oui”, “monument”: “eiffel tower”}
  12. 12. public void travel() { var response = _client .Post(“/paris”, new{name=“Pixie”}) .Send(); if (response.status == 200) { response = _client.Post(“/brussels”, new { monument=response.body.monument }).Send(); // etc }}
  13. 13. > POST /paris> {“name”: “resty galore”}< 200 OK< {“monument”: “eiffel tower”}
  14. 14. > POST /brussels> {“monument”: “eiffel tower”}
  15. 15. Oh no!The Belgium agent was captured and the message is now London!
  16. 16. > POST /brussels> {“monument”: “eiffel tower”}< 410 Gone somewhere colder
  17. 17. We could send an agent toBrussels to warn Resty Galore…
  18. 18. > POST /brussels> {“monument”: “eiffel tower”}< 307 Redirect to London, quick!
  19. 19. Keeping agents in each location we need to redirect is expensive. Travelling for nothing is also expensive.Or Resty Galore could start her journey with…
  20. 20. Keeping agents in each location we need to redirect is expensive.Or Resty Galore could start her journey with…
  21. 21. > POST /paris> {“name”: “resty galore”}< 200 OK< Link: </london>; rel=“next”< {“monument”: “eiffel tower”}
  22. 22. public void travel() { var response = _client .Post(“/paris”, new{name=“Pixie”}) .Send(); if (response.status == 200) { response = _client.Post(response.links.next, new { monument = response.body.monument }).Send(); // etc }}
  23. 23. > POST /london> {“monument”: “eiffel tower”}< 418 I’m a teapot<<<<<
  24. 24. > POST /london> {“monument”: “eiffel tower”}< 200 OK< Link: </copenhagen>; rel=“next”< {“food”: “Chicken Tikka Massala”}
  25. 25. > POST /copenhagen> {“monument”: “eiffel tower”}
  26. 26. Oh no!The Danish wants more security and require both the food and the monument!
  27. 27. > POST /copenhagen> {“monument”: “eiffel tower”}< 400 Bad request dudette
  28. 28. Forms
  29. 29. > GET /copenhagen< 200 OK< {“form”: {< “monument”: null,< “food”: null< }}> POST /copenhagen> {“monument”: “eiffel tower”,> “food”: “Chicken Tikka Massala”}< 200 OK< Link: </malmo>; rel=“next”< {“author”: “hans christian andersen”}
  30. 30. > GET /malmo< 200 OK< {“form”: {< “author”: null< }}
  31. 31. Oh no!The agent in Malmo is a Mole! They have to be decommissioned!
  32. 32. > GET /malmo< 200 OK< {“form”: {< “author”: null< }}> POST /malmo> {“author”: “hans christian andersen”}< 200 OK< {“secret”: “not yet…”}
  33. 33. Forms with control data
  34. 34. > GET /malmo< 200 OK< {“form”: {< “method”: “DELETE”< “href”: “/malmo/mole”< }}> DELETE /malmo/mole> 200 OK< {“secret”: “ReST is amazing.”}
  35. 35. We lowered coupling by…• Respecting the Uniform Interface (status codes, verbs…)• Introducing Links to navigate• Introducing forms to know what to send• Introducing control data in forms to enable a change in workflow with no change in the client code.
  36. 36. • OpenRasta - http://openrasta.org• OpenWrap – http://openwrap.org• Web linking - http://tools.ietf.org/html/rfc5988

×