The document discusses the constraints of REST (REpresentational State Transfer) architectural style. It defines REST as a set of constraints for distributed hypermedia systems. The key constraints are that systems be stateless, cacheable, have a uniform interface, and include hypertext driving application state. The hypermedia constraint requires that hyperlinks define valid state transitions and drive the API, making it RESTful. The document provides examples of how to implement the hypermedia constraint using formats like HTML, Atom, and custom MIME types.
31. “What needs to be done to make the REST
architectural style clear on the notion that
hypertext is a constraint? In other words, if
the engine of application state (and hence
the API) is not being driven by hypertext, then
it cannot be RESTful and cannot be a REST
API. Period.”
Roy Fielding
36. The hypermedia
constraint
The client tells the server what language it speaks
37. The hypermedia
constraint
The server tells the client what to do
38. Hypermedia Types
“Hypermedia Types are MIME media types that contain native
hyper-linking semantics that induce application flow.”
Mike Amundsen (2010)
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