• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
REST and the Hypermedia Constraint

REST and the Hypermedia Constraint






Total Views
Views on SlideShare
Embed Views



1 Embed 1

http://www.linkedin.com 1


Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • \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 ‘why is it so difficult to send a file to someone online?’\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‘Architectural Styles and the Design of Network-based Software Architectures’\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’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’s why it’s been so successful over the last 20 years. The web is 20 years old. That’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’s great for the web as browsers only need to understand GET and POST - this is fine and it’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’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’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 REST and the Hypermedia Constraint Presentation Transcript

  • REST and the Hypermedia Constraint
  • @blongden
  • @ibuildings
  • @fdrop
  • Hands up!
  • RESTREpresentational State Transfer
  • REST“Series of constraints for distributed hypermedia systems” Roy Fielding, 2000
  • 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 latency, enforce security, and encapsulate legacy systems.
  • 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 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
  • 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 application flow.” Mike Amundsen (2010)
  • HTTP
  • HTTPYour browser speaks the language of text/html
  • <!DOCTYPE html>
  • HTTP/1.1
  • 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/media-types/collection/http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
  • https://joind.in/6326 @blongden