SlideShare a Scribd company logo
RESTful Services
What is REST and is it worth the trouble?
OR
How to start an argument with your coworkers.
What is REST?
• REpresentational State Transfer
• Originates from PhD thesis by Roy Felding.
http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.h
tm
• 6 Main Tenets
• Uniform Interface
• Stateless
• Cacheable
• Client-Server
• Layered System
• Code-on-Demand
REST
• Uniform Interface
• Everything is a resource, accessed through URIs
• Stateless
• Client always passes state necessary to complete action
• Cacheable
• Results can be marked as cacheable or not
• Client-Server
• Client and Server are de-coupled
• Layered System
• Client has no knowledge of backend implementation
• Code-on-Demand (optional)
• Client can be extended with code retrieved from server
• JavaScript, Applets, plug-ins, etc
• Of dubious value to APIs
Uniform Interface
• Resource based
• Everything is a URI
• Apply verbs to Resource
• Avoid RPC style invocations
• Don’t replicate SOAP using JSON and MVC Web API.
Layered System
• Don’t expose the implentation on the backend through your API.
• Don’t expose your database tables as a series of REST resources and
operations
• As a general rule, defer decisions (like persistence) as long as possible.
Choose tools that allow you to defer
Richardson Maturity Model
How RESTful is your API?
• Level 0 – Swamp of POX
• Level 1 – Resource Based
• Level 2 – Verbs
• Level 3 – HATEOAS
Created by Leonard Richardson
HATEOAS?
• Not just an evil breakfast cereal.
• Hypermedia As The Engine Of Application State
• Links define what can be done with resource
in current context
{ id: “123”,
_links: [{rel:“self”, href:“/cart/123”},
{rel:“order”, href:“/cart/123/order”}]
• Allows server to provide contextual actions to
client
• Client responds appropriately based on state
What is Hypermedia?
• Media with Hyperlinks, that’s it.
• Media type definitions define how hyperlinks work that media type
• HTML <a href=… />
• XML XLink
• HAL _links
Why is Hypermedia important?
• Discoverability
• Driving State
• Resiliency
Roy’s Smack down
Roy’s Smack down
“API designers, please note the following rules before calling your creation a REST API:”
• “A REST API should not be dependent on any single communication protocol”
• “A REST API should not contain any changes to the communication protocols aside from
filling-out or fixing the details of underspecified bits of standard protocols”
• “A REST API should spend almost all of its descriptive effort in defining the media type(s)
used for representing resources and driving application state”
• “A REST API must not define fixed resource names or hierarchies”
• “A REST API should never have “typed” resources that are significant to the client.”
• “A REST API should be entered with no prior knowledge beyond the initial URI
(bookmark) and set of standardized media types that are appropriate for the intended
audience”
• http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
Roy’s Smack down
“Of course the client has prior knowledge. Every protocol, every media
type definition, every URI scheme, and every link relationship type
constitutes prior knowledge that the client must know (or learn) in
order to make use of that knowledge. REST doesn’t eliminate the need
for a clue. What REST does is concentrate that need for prior
knowledge into readily standardizable forms. That is the essential
distinction between data-oriented and control-oriented integration.
It has value because it is far easier to standardize representation and
relation types than it is to standardize objects and object-specific
interfaces. In other words, there are fewer things to learn and they can
be recombined in unanticipated ways while remaining understandable
to the client.”
Is HTTP required?
• NO
• RestBus, etc.
• HTTP semantics over AMQP
• But...
• HTTP is ubiquitous
• Every platform can talk HTTP
• HTTP Works
• HTTP is easy
Media Types
• application/json
• HAL+JSON
• JSON API
• No Custom types: application/vnd.ebayorder+json
HTTP Verbs
• GET – Retreive a Representation
• POST – Create (Server generated ID)
• PUT – Create OR Replace (Client generated ID)
• PATCH – Update
• DELETE – Delete
• Verbs act on nouns. Represent everything as a noun.
HTTP Response Codes
• Use the most specific response code
• 2XX for Success
• 3XX for Redirections
• 4XX for Client related errors
• 5XX for service related errors
2XX Examples
• 200 OK in response to successful GET
• 201 Created for successful POST
• Location header for location of new resource
• 202 Accepted for async operations
• Location header for polling endpoint
• 200 with status message, 303 once created, 410 GONE once status endpoint no longer
makes sense to keep
• 206 Partial Content for ranged requests
• Use with Range header
• Can be used for paging
3XX Examples
• 302/303 for redirect
• Location header
• 304 Not Modified
• Use with If-Modified-Since or If-None-Match headers
• 307/308
• Temporary vs Permanent Redirect
• VERB cannot change
4XX Examples
• 400 Bad Request
• 401 Unauthorized
• - You’re Not Authenticated
• 403 Forbidden
• You don’t have permission
• 404 Not Found
• Resource doesn’t exist (yet)
• 405 Method (VERB) not allowed
• 409 conflict
• Use with ETags for concurrency
4XX Examples
• 410 Gone
• Resource no longer exists
• Use instead of 404 if you want client to know that it used to exist but doesn’t
anymore
• 429 Too Many Requests
• Use for Rate Limiting
5XX Examples
• 500 Internal Server Error
• Something’s broke
• 502 Bad Gateway
• Can be used if you wish to signal to the client that the problem lies with
another endpoint
• Ex. Client calls your service and your service calls 3rd party that is down.
Versioning
• http://www.troyhunt.com/2014/02/your-api-versioning-is-wrong-
which-is.html
• Require version on each request
• Use API gateway to route requests
• Make non breaking changes when possible
• Deploy to new endpoint on major/breaking changes if backward
compatability is a requirement.
Best Practices
• Require a correlation ID for all requests
• Generate one if client doesn’t provide it
• Always return a payload with error information on 4XX and 5XX
responses
• Use ETags for caching and concurrency
• Prefer X-xxx header naming for custom headers to avoid conflicts
• Use UTC time and ISO8601 format (2016-02-15T23:30:00Z)
• Use Swagger (OpenAPI) for documentation (http://swagger.io/)
References
• http://www.crummy.com/writing/speaking/2008-QCon/act3.html
• http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.h
tm
• http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-
driven
• http://stateless.co/hal_specification.html
• http://www.troyhunt.com/2014/02/your-api-versioning-is-wrong-
which-is.html
• https://www.gitbook.com/book/geemus/http-api-design/details
• http://www.restapitutorial.com/

More Related Content

What's hot

Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2
Christian Posta
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
Rafal Gancarz
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM Alternative
Andrus Adamchik
 
Require js training
Require js trainingRequire js training
Require js training
Dr. Awase Khirni Syed
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
Henry S
 
Middleware in Golang: InVision's Rye
Middleware in Golang: InVision's RyeMiddleware in Golang: InVision's Rye
Middleware in Golang: InVision's Rye
Cale Hoopes
 
ActiveMQ Performance Tuning
ActiveMQ Performance TuningActiveMQ Performance Tuning
ActiveMQ Performance TuningChristian Posta
 
ActiveMQ 5.9.x new features
ActiveMQ 5.9.x new featuresActiveMQ 5.9.x new features
ActiveMQ 5.9.x new features
Christian Posta
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
Ngoc Dao
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swagger
Tony Tam
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Wen-Tien Chang
 
Xitrum HOWTOs
Xitrum HOWTOsXitrum HOWTOs
Xitrum HOWTOsNgoc Dao
 
Open source identity management 20121106 - apache con eu
Open source identity management   20121106 - apache con euOpen source identity management   20121106 - apache con eu
Open source identity management 20121106 - apache con euFrancesco Chicchiriccò
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy Behaviours
J V
 
Json api dos and dont's
Json api dos and dont'sJson api dos and dont's
Json api dos and dont's
Neven Rakonić
 
RESTful Rails2
RESTful Rails2RESTful Rails2
RESTful Rails2
Wen-Tien Chang
 
Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief Overview
Craig Dickson
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World

What's hot (20)

Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
 
Apache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM AlternativeApache Cayenne: a Java ORM Alternative
Apache Cayenne: a Java ORM Alternative
 
Require js training
Require js trainingRequire js training
Require js training
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Middleware in Golang: InVision's Rye
Middleware in Golang: InVision's RyeMiddleware in Golang: InVision's Rye
Middleware in Golang: InVision's Rye
 
ActiveMQ Performance Tuning
ActiveMQ Performance TuningActiveMQ Performance Tuning
ActiveMQ Performance Tuning
 
ActiveMQ 5.9.x new features
ActiveMQ 5.9.x new featuresActiveMQ 5.9.x new features
ActiveMQ 5.9.x new features
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swagger
 
On being RESTful
On being RESTfulOn being RESTful
On being RESTful
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3Service-Oriented Design and Implement with Rails3
Service-Oriented Design and Implement with Rails3
 
Xitrum HOWTOs
Xitrum HOWTOsXitrum HOWTOs
Xitrum HOWTOs
 
Open source identity management 20121106 - apache con eu
Open source identity management   20121106 - apache con euOpen source identity management   20121106 - apache con eu
Open source identity management 20121106 - apache con eu
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy Behaviours
 
Json api dos and dont's
Json api dos and dont'sJson api dos and dont's
Json api dos and dont's
 
RESTful Rails2
RESTful Rails2RESTful Rails2
RESTful Rails2
 
Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief Overview
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 

Similar to RESTful Services

Rest APIs Training
Rest APIs TrainingRest APIs Training
Rest APIs Training
Shekhar Kumar
 
What is REST?
What is REST?What is REST?
What is REST?
Saeid Zebardast
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service DesignLorna Mitchell
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan UllahOverview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
Cefalo
 
Introduction to Restful Web Services
Introduction to Restful Web ServicesIntroduction to Restful Web Services
Introduction to Restful Web Services
weili_at_slideshare
 
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
Ram Awadh Prasad, PMP
 
Best Practice in Web Service Design
Best Practice in Web Service DesignBest Practice in Web Service Design
Best Practice in Web Service Design
Lorna Mitchell
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API RecommendationsJeelani Shaik
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
Siddharth Sharma
 
ReST
ReSTReST
Rest
RestRest
CNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application TechnologiesCNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application Technologies
Sam Bowne
 
Api crash
Api crashApi crash
Api crash
Hoang Nguyen
 
A Look at OData
A Look at ODataA Look at OData
A Look at OData
Woodruff Solutions LLC
 

Similar to RESTful Services (20)

Rest APIs Training
Rest APIs TrainingRest APIs Training
Rest APIs Training
 
What is REST?
What is REST?What is REST?
What is REST?
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service Design
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan UllahOverview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
 
Introduction to Restful Web Services
Introduction to Restful Web ServicesIntroduction to Restful Web Services
Introduction to Restful Web Services
 
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
 
Best Practice in Web Service Design
Best Practice in Web Service DesignBest Practice in Web Service Design
Best Practice in Web Service Design
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
 
ReST
ReSTReST
ReST
 
Rest
RestRest
Rest
 
CNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application TechnologiesCNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application Technologies
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
A Look at OData
A Look at ODataA Look at OData
A Look at OData
 

Recently uploaded

Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 

Recently uploaded (20)

Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 

RESTful Services

  • 1. RESTful Services What is REST and is it worth the trouble? OR How to start an argument with your coworkers.
  • 2. What is REST? • REpresentational State Transfer • Originates from PhD thesis by Roy Felding. http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.h tm • 6 Main Tenets • Uniform Interface • Stateless • Cacheable • Client-Server • Layered System • Code-on-Demand
  • 3. REST • Uniform Interface • Everything is a resource, accessed through URIs • Stateless • Client always passes state necessary to complete action • Cacheable • Results can be marked as cacheable or not • Client-Server • Client and Server are de-coupled • Layered System • Client has no knowledge of backend implementation • Code-on-Demand (optional) • Client can be extended with code retrieved from server • JavaScript, Applets, plug-ins, etc • Of dubious value to APIs
  • 4. Uniform Interface • Resource based • Everything is a URI • Apply verbs to Resource • Avoid RPC style invocations • Don’t replicate SOAP using JSON and MVC Web API.
  • 5. Layered System • Don’t expose the implentation on the backend through your API. • Don’t expose your database tables as a series of REST resources and operations • As a general rule, defer decisions (like persistence) as long as possible. Choose tools that allow you to defer
  • 6. Richardson Maturity Model How RESTful is your API? • Level 0 – Swamp of POX • Level 1 – Resource Based • Level 2 – Verbs • Level 3 – HATEOAS Created by Leonard Richardson
  • 7. HATEOAS? • Not just an evil breakfast cereal. • Hypermedia As The Engine Of Application State • Links define what can be done with resource in current context { id: “123”, _links: [{rel:“self”, href:“/cart/123”}, {rel:“order”, href:“/cart/123/order”}] • Allows server to provide contextual actions to client • Client responds appropriately based on state
  • 8. What is Hypermedia? • Media with Hyperlinks, that’s it. • Media type definitions define how hyperlinks work that media type • HTML <a href=… /> • XML XLink • HAL _links
  • 9. Why is Hypermedia important? • Discoverability • Driving State • Resiliency
  • 11. Roy’s Smack down “API designers, please note the following rules before calling your creation a REST API:” • “A REST API should not be dependent on any single communication protocol” • “A REST API should not contain any changes to the communication protocols aside from filling-out or fixing the details of underspecified bits of standard protocols” • “A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state” • “A REST API must not define fixed resource names or hierarchies” • “A REST API should never have “typed” resources that are significant to the client.” • “A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience” • http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
  • 12. Roy’s Smack down “Of course the client has prior knowledge. Every protocol, every media type definition, every URI scheme, and every link relationship type constitutes prior knowledge that the client must know (or learn) in order to make use of that knowledge. REST doesn’t eliminate the need for a clue. What REST does is concentrate that need for prior knowledge into readily standardizable forms. That is the essential distinction between data-oriented and control-oriented integration. It has value because it is far easier to standardize representation and relation types than it is to standardize objects and object-specific interfaces. In other words, there are fewer things to learn and they can be recombined in unanticipated ways while remaining understandable to the client.”
  • 13. Is HTTP required? • NO • RestBus, etc. • HTTP semantics over AMQP • But... • HTTP is ubiquitous • Every platform can talk HTTP • HTTP Works • HTTP is easy
  • 14. Media Types • application/json • HAL+JSON • JSON API • No Custom types: application/vnd.ebayorder+json
  • 15. HTTP Verbs • GET – Retreive a Representation • POST – Create (Server generated ID) • PUT – Create OR Replace (Client generated ID) • PATCH – Update • DELETE – Delete • Verbs act on nouns. Represent everything as a noun.
  • 16. HTTP Response Codes • Use the most specific response code • 2XX for Success • 3XX for Redirections • 4XX for Client related errors • 5XX for service related errors
  • 17. 2XX Examples • 200 OK in response to successful GET • 201 Created for successful POST • Location header for location of new resource • 202 Accepted for async operations • Location header for polling endpoint • 200 with status message, 303 once created, 410 GONE once status endpoint no longer makes sense to keep • 206 Partial Content for ranged requests • Use with Range header • Can be used for paging
  • 18. 3XX Examples • 302/303 for redirect • Location header • 304 Not Modified • Use with If-Modified-Since or If-None-Match headers • 307/308 • Temporary vs Permanent Redirect • VERB cannot change
  • 19. 4XX Examples • 400 Bad Request • 401 Unauthorized • - You’re Not Authenticated • 403 Forbidden • You don’t have permission • 404 Not Found • Resource doesn’t exist (yet) • 405 Method (VERB) not allowed • 409 conflict • Use with ETags for concurrency
  • 20. 4XX Examples • 410 Gone • Resource no longer exists • Use instead of 404 if you want client to know that it used to exist but doesn’t anymore • 429 Too Many Requests • Use for Rate Limiting
  • 21. 5XX Examples • 500 Internal Server Error • Something’s broke • 502 Bad Gateway • Can be used if you wish to signal to the client that the problem lies with another endpoint • Ex. Client calls your service and your service calls 3rd party that is down.
  • 22. Versioning • http://www.troyhunt.com/2014/02/your-api-versioning-is-wrong- which-is.html • Require version on each request • Use API gateway to route requests • Make non breaking changes when possible • Deploy to new endpoint on major/breaking changes if backward compatability is a requirement.
  • 23. Best Practices • Require a correlation ID for all requests • Generate one if client doesn’t provide it • Always return a payload with error information on 4XX and 5XX responses • Use ETags for caching and concurrency • Prefer X-xxx header naming for custom headers to avoid conflicts • Use UTC time and ISO8601 format (2016-02-15T23:30:00Z) • Use Swagger (OpenAPI) for documentation (http://swagger.io/)
  • 24. References • http://www.crummy.com/writing/speaking/2008-QCon/act3.html • http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.h tm • http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext- driven • http://stateless.co/hal_specification.html • http://www.troyhunt.com/2014/02/your-api-versioning-is-wrong- which-is.html • https://www.gitbook.com/book/geemus/http-api-design/details • http://www.restapitutorial.com/