REST and the Hypermedia      Constraint
@blongden
@ibuildings
@fdrop
Hands up!
RESTREpresentational State Transfer
REST“Series of constraints for distributed hypermedia systems”                                             Roy Fielding, 2...
Constraints are good
Constraints are goodThey (help) stop you doing crazy things
REST is an Architecture     It is not a protocol
Goals•   Scalability•   Generality of Interfaces•   Independent deployment of components•   Intermediaries to reduce laten...
Client server
Stateless
Cache
Layered system
Code on demand
Uniform interface
Uniform interface   Identification of resources
Uniform interfaceManipulations of resources through representations
Uniform interface   Self descriptive messages
Uniform interfaceHypertext as the engine of application state
“What needs to be done to make the REST   architectural style clear on the notion thathypertext is a constraint? In other ...
The hypermedia  constraint
The hypermedia     constraintA URI request returns all valid state changes
The hypermedia  constraint  It’s how the web works
The hypermedia  constraint  You already understand it!
The hypermedia        constraintThe client tells the server what language it speaks
The hypermedia  constraintThe server tells the client what to do
Hypermedia Types“Hypermedia Types are MIME media types that contain native    hyper-linking semantics that induce applicat...
HTTP
HTTPYour browser speaks the language of text/html
<!DOCTYPE html>
HTTP/1.1
HTTP/1.1HEAD GET POST PUT DELETE TRACE OPTIONS           CONNECT PATCH
GET and POST is OK
GET and POST is OKREST doesn’t care what methods you use
GET and POST is OKHTTP cares that the methods are used correctly
Life in XHTML The website is also the API
Life in XHTMLInconvenient and difficult to maintain
False start #1Attempt a custom hypermedia type
False start #2  application/atom+xml
False start #3  application/xhtml+xml
Custom hypermedia types   Consider registered types first
Custom hypermedia types   More likely to be understood
A solutionapplication/vnd.fdrop.xhtml+xml
A solutionXHTML has hypermedia controls built in
A solutionContains most of what I need
Let’s see it then!     @RESTConsole
XMLit’s really good for this stuff
What about JSON?  application/vnd.collection+json        application/hal+json
Versioninghttp://www.w3.org/History/19921103-hypertext/       hypertext/WWW/TheProject.html
VersioningThe server makes no assumptions on the capabilities of                     the client
VersioningIf the client does not support something, it simply                     ignores it
VersioningThe web is not versioned
VersioningCorrect use of hypermedia means you can change         things without affecting clients
Versioning But if you must...
Versioning Accept: application/vnd.fdrop.xhtml+xmlAccept: application/vnd.fdrop.v2.xhtml+xml
#restirc.freenode.net
http://tools.ietf.org/html/rfc2616http://tools.ietf.org/html/rfc4287http://amundsen.com/hypermedia/http://amundsen.com/med...
https://joind.in/6326    @blongden
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
Upcoming SlideShare
Loading in …5
×

REST and the Hypermedia Constraint

2,697 views

Published on

Published in: Technology, News & Politics
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,697
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
45
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • Developer for 20 years (started young)\nProfessional developer since 2002\nStarted on C, C++ and Perl\nFocussed on Perl and moved into web app development where I picked up PHP\nNow interested in the mobile web, standards and software architectures\n
  • \n
  • \n
  • \n
  • Technical Assurance Manager since the start of 2010\nOne of the Sheffield office founders\n
  • Sole developer of fdrop.it\nCreated to solve my problem of &amp;#x2018;why is it so difficult to send a file to someone online?&amp;#x2019;\n
  • \n
  • Who knows what Rest is?\nKeep your hand up if you know what Hypermedia is.\n
  • \n
  • one of the principle author of HTTP specification (RFC 2616)\nIn 1999 he was named my MIT Technology Review as one of the top 100 innovators in the world under 35\n\n&amp;#x2018;Architectural Styles and the Design of Network-based Software Architectures&amp;#x2019;\n
  • \n
  • Constraints help to guide the creative project\n\nSacrifice is usually made retroactively\n
  • Can be applied to ANY distributed system\nWeb application or API design\n
  • \n
  • Clients not concerned about data storage\nServers not concerned about the user interface or user state\ncomponents evolve independently if interface remains constant\n
  • Each request from the client must contain ALL of the information required\nCannot rely on stored context on the server\nSession state on the client\nVisibility (Server can be observed at any time)\nReliability (network failure)\nScalability (easy to add servers)\n
  • Responses must implicitly or explicitly define themselves as cacheable or not\nFurther improves scalability and performance\n
  • Client connected to the end server or to an intermediary along the way.\nLoad Balancers\nSecurity Policies at a Firewall\nReverse Proxy Cache\n
  • Service can temporarily extend client side functionality by providing code it can execute \nie, Javascript or java applets\n\nTHE OPTIONAL CONSTRAINT!\n
  • Information is transferred in a standardised form.\nFour guiding principles to simplify architecture\n
  • On the web we use URI&amp;#x2019;s\n\nResources themselves are usually different to what is returned to the client\nUsually, a database resource will be represented in JSON or XML\n
  • Each resource can have one or more representations.\nClients negotiate (con-neg) to agree on format.\n
  • Requests contain data and additional headers on how it should be handled\nEach message describes itself. This means using an explicit mime type, and explicitly if the resource can be cached.\n
  • Clients make state transitions ONLY through links returned within the resource (ie, anchors in html)\nOnly exception is the entry point\n
  • \n
  • \n
  • \n
  • and it&amp;#x2019;s why it&amp;#x2019;s been so successful over the last 20 years. The web is 20 years old. That&amp;#x2019;s amazing - and because of standards and hypermedia, I can still reference things from 20 years ago.\n
  • A web page contains all the information within it to allow the user to move from the current state, to the next.\n
  • \n
  • content negotiation\n
  • HTML is a hypermedia type\nXML is not\n
  • All types of HTML\nXHTML\n\nVersions within them are identified by the content (DOCTYPE, html tag or xml header)\nXML documents not processed as XML (no checks for well formedness)\n \n
  • This is how you declare an html 5 document. It&amp;#x2019;s great for the web as browsers only need to understand GET and POST - this is fine and it&amp;#x2019;s still RESTful, but what if we need a representation of a resource that can support other actions?\n
  • \nHTTP 1.1 defines these 9 methods. HTML lets us use 2 of them. \n
  • That&amp;#x2019;s all you get in a browser\n\n
  • \n
  • GET to retrive, POST to create, PUT to update, DELETE\nPOST to a job queue to update and delete\nThese are HTTP, not REST (REST just defines the uniform interface)\n
  • \n
  • Focus on the UI breaks the API\n
  • Craft my own XML doc\nNeed to define my media type first\nToo much like work...\n
  • There was merit to this - which i&amp;#x2019;ll come back to\n
  • Remove the markup from the XHTML that was only there to layout the UI\nServe HTML5 to browsers on text/html!\nClose - but webkit on iOS and Android devices prefer XML\n
  • \n
  • \n
  • XHTML still in the media type so still self describing\nWont conflict with browsers\n\n
  • \n\n
  • form, input, img, a\nBrowsers already understand XHTML\nEasy for people to consume using any XML Reader\nDEMO\n
  • \n
  • Namespaces\nAttributes and values\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • REST and the Hypermedia Constraint

    1. 1. REST and the Hypermedia Constraint
    2. 2. @blongden
    3. 3. @ibuildings
    4. 4. @fdrop
    5. 5. Hands up!
    6. 6. RESTREpresentational State Transfer
    7. 7. REST“Series of constraints for distributed hypermedia systems” Roy Fielding, 2000
    8. 8. Constraints are good
    9. 9. Constraints are goodThey (help) stop you doing crazy things
    10. 10. REST is an Architecture It is not a protocol
    11. 11. Goals• Scalability• Generality of Interfaces• Independent deployment of components• Intermediaries to reduce latency, enforce security, and encapsulate legacy systems.
    12. 12. Client server
    13. 13. Stateless
    14. 14. Cache
    15. 15. Layered system
    16. 16. Code on demand
    17. 17. Uniform interface
    18. 18. Uniform interface Identification of resources
    19. 19. Uniform interfaceManipulations of resources through representations
    20. 20. Uniform interface Self descriptive messages
    21. 21. Uniform interfaceHypertext as the engine of application state
    22. 22. “What needs to be done to make the REST architectural style clear on the notion thathypertext is a constraint? In other words, if the engine of application state (and hencethe API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. Period.” Roy Fielding
    23. 23. The hypermedia constraint
    24. 24. The hypermedia constraintA URI request returns all valid state changes
    25. 25. The hypermedia constraint It’s how the web works
    26. 26. The hypermedia constraint You already understand it!
    27. 27. The hypermedia constraintThe client tells the server what language it speaks
    28. 28. The hypermedia constraintThe server tells the client what to do
    29. 29. Hypermedia Types“Hypermedia Types are MIME media types that contain native hyper-linking semantics that induce application flow.” Mike Amundsen (2010)
    30. 30. HTTP
    31. 31. HTTPYour browser speaks the language of text/html
    32. 32. <!DOCTYPE html>
    33. 33. HTTP/1.1
    34. 34. HTTP/1.1HEAD GET POST PUT DELETE TRACE OPTIONS CONNECT PATCH
    35. 35. GET and POST is OK
    36. 36. GET and POST is OKREST doesn’t care what methods you use
    37. 37. GET and POST is OKHTTP cares that the methods are used correctly
    38. 38. Life in XHTML The website is also the API
    39. 39. Life in XHTMLInconvenient and difficult to maintain
    40. 40. False start #1Attempt a custom hypermedia type
    41. 41. False start #2 application/atom+xml
    42. 42. False start #3 application/xhtml+xml
    43. 43. Custom hypermedia types Consider registered types first
    44. 44. Custom hypermedia types More likely to be understood
    45. 45. A solutionapplication/vnd.fdrop.xhtml+xml
    46. 46. A solutionXHTML has hypermedia controls built in
    47. 47. A solutionContains most of what I need
    48. 48. Let’s see it then! @RESTConsole
    49. 49. XMLit’s really good for this stuff
    50. 50. What about JSON? application/vnd.collection+json application/hal+json
    51. 51. Versioninghttp://www.w3.org/History/19921103-hypertext/ hypertext/WWW/TheProject.html
    52. 52. VersioningThe server makes no assumptions on the capabilities of the client
    53. 53. VersioningIf the client does not support something, it simply ignores it
    54. 54. VersioningThe web is not versioned
    55. 55. VersioningCorrect use of hypermedia means you can change things without affecting clients
    56. 56. Versioning But if you must...
    57. 57. Versioning Accept: application/vnd.fdrop.xhtml+xmlAccept: application/vnd.fdrop.v2.xhtml+xml
    58. 58. #restirc.freenode.net
    59. 59. http://tools.ietf.org/html/rfc2616http://tools.ietf.org/html/rfc4287http://amundsen.com/hypermedia/http://amundsen.com/media-types/collection/http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
    60. 60. https://joind.in/6326 @blongden

    ×