SlideShare a Scribd company logo
1 of 66
REST and HATEOAS



Ben Longden, PHPNW 2011
REST and the
Hypermedia Constraint



Ben Longden, PHPNW 2011
Who are you?
Who are you?
   @blongden
Who are you?
Who are you?
   @ibuildings
Who are you?
Who are you?
    @fdrop
REST
REpresentational State Transfer
REST
 Series of constraints for distributed
hypermedia systems - Roy Fielding, 2000
Constraints are good
Constraints are good
They (help) stop you from 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 interface
Manipulations of resources through
          representations
Uniform interface
  Self descriptive messages
Uniform interface
Hypertext as the engine of application
                 state
The hypermedia
  constraint?
The hypermedia
      constraint
A URI request returns all valid state
               changes
The hypermedia
  constraint
 It’s how the web works
The hypermedia
  constraint
You already understand it!
HTTP
HTTP
Your browser speaks the language of
             text/html
<!DOCTYPE html>
HTML
Using hypermedia on the web, you can
   link to different types of data
HTML
Using hypermedia on the web, you can
   link to different types of data


 text/css image/png audio/mpeg
Hypermedia Types
 “Hypermedia Types are MIME media types
    that contain native hyper-linking
semantics that induce application flow.”
          - Mike Amundsen (2010)
The hypermedia
    constraint
The client tells the server what
       language it speaks
The hypermedia
       constraint
The server tells the client what to do
HTTP/1.1
HTTP/1.1
HEAD GET POST PUT DELETE TRACE OPTIONS
             CONNECT PATCH
GET and POST is OK
GET and POST is OK
REST doesn’t care what methods you use
GET and POST is OK
HTTP cares that the methods are used
              correctly
Life in XHTML
The website is also the API
Life in XHTML
Inconvenient and difficult to maintain
False start #1
Attempt 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 solution
application/vnd.fdrop.xhtml+xml
A solution
XHTML has hypermedia controls built in
A solution
Contains most of what I need
XML based media
     types
    Namespaces
Let’s see it then!
     @RESTConsole
What about JSON?
application/vnd.collection+json
      application/hal+json
Versioning
  http://www.w3.org/History/19921103-
hypertext/hypertext/WWW/TheProject.html
Versioning
The server makes no assumptions on the
      capabilities of the client
Versioning
 If the client does not support
something, it simply ignores it
Versioning
The web is not versioned
Versioning
Correct use of hypermedia means you can
change things without affecting clients
Versioning
But if you must...
Versioning
Accept: application/vnd.fdrop.v2.xhtml+xml
http://tools.ietf.org/html/rfc2616
http://tools.ietf.org/html/rfc4287
http://amundsen.com/hypermedia/
http://amundsen.com/media-types/collection/

http://www.flickr.com/photos/bjornmeansbear/4727475559/
http://joind.in/talk/view/3589

          @blongden

More Related Content

What's hot

ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 

What's hot (20)

Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
APIs, REST e RESTful: O que os programadores precisam saber? - Marcos Echevar...
APIs, REST e RESTful: O que os programadores precisam saber? - Marcos Echevar...APIs, REST e RESTful: O que os programadores precisam saber? - Marcos Echevar...
APIs, REST e RESTful: O que os programadores precisam saber? - Marcos Echevar...
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOAS
 
introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST API
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Soap web service
Soap web serviceSoap web service
Soap web service
 
REST API
REST APIREST API
REST API
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
 
SOAP vs REST
SOAP vs RESTSOAP vs REST
SOAP vs REST
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 

Similar to Rest and the hypermedia constraint

REST and the Hypermedia Constraint
REST and the Hypermedia ConstraintREST and the Hypermedia Constraint
REST and the Hypermedia Constraint
Inviqa
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
Cathie101
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
Cathie101
 
Lecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptxLecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptx
Kevi20
 

Similar to Rest and the hypermedia constraint (20)

REST and the Hypermedia Constraint
REST and the Hypermedia ConstraintREST and the Hypermedia Constraint
REST and the Hypermedia Constraint
 
internet principles of operation By ZAK
internet principles of operation By ZAKinternet principles of operation By ZAK
internet principles of operation By ZAK
 
HTTP: the Other ESB
HTTP: the Other ESBHTTP: the Other ESB
HTTP: the Other ESB
 
HTTP1.1/2 overview
HTTP1.1/2 overviewHTTP1.1/2 overview
HTTP1.1/2 overview
 
RESTful APIs
RESTful APIsRESTful APIs
RESTful APIs
 
Web
WebWeb
Web
 
Web technology-guide
Web technology-guideWeb technology-guide
Web technology-guide
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1
 
RESTful web services using java and spring
RESTful web services using java and springRESTful web services using java and spring
RESTful web services using java and spring
 
Http_Protocol.pptx
Http_Protocol.pptxHttp_Protocol.pptx
Http_Protocol.pptx
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
Web Services 2009
Web Services 2009Web Services 2009
Web Services 2009
 
Web programming by Najeeb ullahAzad(1)
Web programming by Najeeb ullahAzad(1)Web programming by Najeeb ullahAzad(1)
Web programming by Najeeb ullahAzad(1)
 
ASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP FundamentalsASP.NET Web API and HTTP Fundamentals
ASP.NET Web API and HTTP Fundamentals
 
Session 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdfSession 8 Android Web Services - Part 1.pdf
Session 8 Android Web Services - Part 1.pdf
 
Web server
Web serverWeb server
Web server
 
0130225347
01302253470130225347
0130225347
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Lecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptxLecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptx
 
11 asp.net web api
11 asp.net web api11 asp.net web api
11 asp.net web api
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Rest and the hypermedia constraint

Editor's Notes

  1. \n
  2. \n
  3. Developer for 20 years\nProfessional developer since 2002\nStarted on C, C++ and Perl\nFocussed on Perl and moved into web app development where I picked up PHP\nmobile web, standards and software architectures\n
  4. Technical Team Lead since the start of 2010\nOne of the Sheffield office founders\n
  5. 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
  6. \n
  7. \n
  8. Doctoral Dissertation\n&amp;#x2018;Architectural Styles and the Design of Network-based Software Architectures&amp;#x2019;\n\none of the principle author of HTTP specification (RFC 1945/2616)\nIn 1999 he was named my MIT Technology Review as one of the top 100 innovators in the world under 35\n\n\n
  9. \n
  10. Constraints help to guide the creative project\n\nSacrifice is usually made retroactively\n
  11. Can be applied to ANY distributed system\nWeb application or API design\n
  12. \n
  13. Clients not concerned about data storage\nServers not concerned about the user interface or user state\ncomponents evolve independently if interface remains constant\n
  14. 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), Reliability (network failure), Scalability (easy to add servers)\n
  15. Responses must implicitly or explicitly define themselves as cacheable or not\nFurther improves scalability and performance\n\n
  16. Client connected to the end server or to an intermediary along the way.\nLoad Balancers\nSecurity Policies at a Firewall\nReverse Proxy Cache\n\n
  17. Service can temporarily extend client side functionality by providing code it can execute \nie, Javascript or java applets\n\nTHE OPTIONAL CONSTRAINT!\n
  18. Four guiding principles to simplify architecture\n
  19. 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
  20. When a client holds a representation, it is enough to be able to modify or delete the resource assuming the user has permission to do so\n
  21. Each message describes itself. This means using an explicit mime type, and explicitly if the resource can be cached.\n
  22. Clients make state transitions ONLY through links returned within the resource (ie, anchors in html)\n\nOnly exception is the entry point\n
  23. HATEOAS is a horrible acronym\n
  24. Using hypermedia (anchor, xlink, etc)\n
  25. 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
  26. A web page contains all the information within it to allow the user to move from the current state, to the next.\n
  27. 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
  28. HTML 5 won over XHTML for who gains supremacy over the browsers - HTML contains some really good stuff about describing text, images, user input etc and what HTTP function to use on them (ie, GET image, POST a form).\n
  29. 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
  30. \n
  31. HTML is a hypermedia type\nXML is not\n
  32. Accept header in HTTP\n
  33. HTTP headers and Hypermedia!\n
  34. \nHTTP 1.1 defines these 9 methods. HTML lets us use 2 of them. \n
  35. That&amp;#x2019;s all you get in a browser\n\n
  36. \n
  37. 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
  38. API for free?\nDownsides\nSome actions need to be different over an API due to different UI\nAJAX\n
  39. Focus on the UI breaks the API\n
  40. Craft my own XML doc\nNeed to define my media type first\nToo much like work...\n
  41. There was merit to this - which i&amp;#x2019;ll come back to\n
  42. 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
  43. \n
  44. \n
  45. XHTML still in the media type so still self describing\nWont conflict with browsers\n\n
  46. \n\n
  47. form, input, img, a\nBrowsers already understand XHTML\nEasy for people to consume using any XML Reader\nDEMO\n
  48. XHTML only supports GET and POST\nWhat if we need more?\n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n