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
 
Apache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya KulkarniApache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya Kulkarni
webhostingguy
 
Apache web server
Apache web serverApache web server
Apache web server
zrstoppe
 

What's hot (20)

ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
Html training slide
Html training slideHtml training slide
Html training slide
 
Basics of HTTP - Nafis Fuad
Basics of HTTP - Nafis FuadBasics of HTTP - Nafis Fuad
Basics of HTTP - Nafis Fuad
 
Apache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya KulkarniApache Web Server Architecture Chaitanya Kulkarni
Apache Web Server Architecture Chaitanya Kulkarni
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
 
Apache web server
Apache web serverApache web server
Apache web server
 
Soap vs rest
Soap vs restSoap vs rest
Soap vs rest
 
Asp.net caching
Asp.net cachingAsp.net caching
Asp.net caching
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Apache web server
Apache web serverApache web server
Apache web server
 
Web server
Web serverWeb server
Web server
 
WS-Privacy,
WS-Privacy,WS-Privacy,
WS-Privacy,
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Apache Server Tutorial
Apache Server TutorialApache Server Tutorial
Apache Server Tutorial
 
Api presentation
Api presentationApi presentation
Api presentation
 
CSS ppt
CSS pptCSS ppt
CSS ppt
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 

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

Recently uploaded (20)

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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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