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.

Rest and the hypermedia constraint

7,957 views

Published on

A RESTful API is only truly RESTful if it uses hypermedia to tell us about all the actions that can be performed on the curent resource, allowing us to traverse the API from a single entry point.

His session looks at REST and HATEOAS (Hypermedia As The Engine Of Application State) to illustrate good service structure. Ben will use the RESTful file sharing service fdrop.it to illustrate the various examples of how this can be used.

This session is recommended for architects and senior developers alike and will give a good grounding in writing excellent, self-explanatory RESTful services.

Published in: Technology, News & Politics
  • Be the first to comment

Rest and the hypermedia constraint

  1. 1. REST and HATEOASBen Longden, PHPNW 2011
  2. 2. REST and theHypermedia ConstraintBen Longden, PHPNW 2011
  3. 3. Who are you?
  4. 4. Who are you? @blongden
  5. 5. Who are you?
  6. 6. Who are you? @ibuildings
  7. 7. Who are you?
  8. 8. Who are you? @fdrop
  9. 9. RESTREpresentational State Transfer
  10. 10. REST Series of constraints for distributedhypermedia systems - Roy Fielding, 2000
  11. 11. Constraints are good
  12. 12. Constraints are goodThey (help) stop you from doing crazy things
  13. 13. REST is an Architecture It is not a protocol
  14. 14. GoalsScalabilityGenerality of InterfacesIndependent deployment of componentsIntermediaries to reduce latency,enforce security, and encapsulatelegacy systems.
  15. 15. Client server
  16. 16. Stateless
  17. 17. Cache
  18. 18. Layered system
  19. 19. Code on demand
  20. 20. Uniform interface
  21. 21. Uniform interface Identification of resources
  22. 22. Uniform interfaceManipulations of resources through representations
  23. 23. Uniform interface Self descriptive messages
  24. 24. Uniform interfaceHypertext as the engine of application state
  25. 25. The hypermedia constraint?
  26. 26. The hypermedia constraintA URI request returns all valid state changes
  27. 27. The hypermedia constraint It’s how the web works
  28. 28. The hypermedia constraintYou already understand it!
  29. 29. HTTP
  30. 30. HTTPYour browser speaks the language of text/html
  31. 31. <!DOCTYPE html>
  32. 32. HTMLUsing hypermedia on the web, you can link to different types of data
  33. 33. HTMLUsing hypermedia on the web, you can link to different types of data text/css image/png audio/mpeg
  34. 34. Hypermedia Types “Hypermedia Types are MIME media types that contain native hyper-linkingsemantics that induce application flow.” - Mike Amundsen (2010)
  35. 35. The hypermedia constraintThe client tells the server what language it speaks
  36. 36. The hypermedia constraintThe server tells the client what to do
  37. 37. HTTP/1.1
  38. 38. HTTP/1.1HEAD GET POST PUT DELETE TRACE OPTIONS CONNECT PATCH
  39. 39. GET and POST is OK
  40. 40. GET and POST is OKREST doesn’t care what methods you use
  41. 41. GET and POST is OKHTTP cares that the methods are used correctly
  42. 42. Life in XHTMLThe website is also the API
  43. 43. Life in XHTMLInconvenient and difficult to maintain
  44. 44. False start #1Attempt a custom hypermedia type
  45. 45. False start #2 application/atom+xml
  46. 46. False start #3 application/xhtml+xml
  47. 47. Custom hypermedia types Consider registered types first
  48. 48. Custom hypermedia types More likely to be understood
  49. 49. A solutionapplication/vnd.fdrop.xhtml+xml
  50. 50. A solutionXHTML has hypermedia controls built in
  51. 51. A solutionContains most of what I need
  52. 52. XML based media types Namespaces
  53. 53. Let’s see it then! @RESTConsole
  54. 54. What about JSON?application/vnd.collection+json application/hal+json
  55. 55. Versioning http://www.w3.org/History/19921103-hypertext/hypertext/WWW/TheProject.html
  56. 56. VersioningThe server makes no assumptions on the capabilities of the client
  57. 57. Versioning If the client does not supportsomething, it simply ignores it
  58. 58. VersioningThe web is not versioned
  59. 59. VersioningCorrect use of hypermedia means you canchange things without affecting clients
  60. 60. VersioningBut if you must...
  61. 61. VersioningAccept: application/vnd.fdrop.v2.xhtml+xml
  62. 62. http://tools.ietf.org/html/rfc2616http://tools.ietf.org/html/rfc4287http://amundsen.com/hypermedia/http://amundsen.com/media-types/collection/http://www.flickr.com/photos/bjornmeansbear/4727475559/
  63. 63. http://joind.in/talk/view/3589 @blongden

×