SlideShare a Scribd company logo
1 of 13
RESTful Design Rules
Why? – adds value
• Encourages a Contract-First API service
• Rules help design for scalable services
• Establishes a design standard and language
• Rules promotes a “crisp”API making happy clients,
reducing Support costs and sells the API (Netflix,
Google, Github)
• Sources : Apache project, Roy Fielding thesis
• “Rest API Design Rule Book” - Mark Masse
(O'Reilly Pub)
Web Architecture Scalability
Constraints
• Client-Server: must play distinct roles
• Uniform Interface: standard interaction
between client and server components
• Cache : reduce latency, improve availability.
Client or server
• Stateless: resource at server has no state. Only
client has conversational state
Uniform Interface
• Identify service resources with an address: URI
• Resource representation – resource returns
different representations to different clients
• Self descriptive – desired resource state
reflected in request and current state in
response. An update is successful or not
• Links(HATEOAS) – current state defines links to
related allowed links, may depend on client
Questions
• How do I design for self-descriptive messages?
• REST models state – how do I model this?
• What URI name shall I use for CRUD services?
• What URI name shall I use for non-CRUD
services?
• What HTTP response status codes to use for
use cases?
REST Modeling
• HTTP methods for CRUD or non-CRUD services
• Document/Resource – object, record : animal
• Collection resource – many related objects:
animals (=database)
• Store resource – many unrelated documents
• Controller resource – process resource
• Idempotent – side affect free
• URI path – hierarchy of resources; /cats/felix
HTTP Method-Service Map
• GET(SELECT) – Retrieve document(s)
• POST(CREATE) – Create a new resource in a
collection
• POST(PROCESS) – Perform non-CRUD process
• PUT(UPDATE) – Update resource
• DELETE(DELETE) – Delete resource
• PATCH(UPDATE) – Update with changes
• HEAD – Get metadata or “ping” resource
• OPTIONS – Get resource’s “Allowed” URI links
Recommended Status Codes
• 200 OK – [GET]
• 201 CREATED – [POST/PUT/PATCH]
• 202 ACCEPTED – [POST], async action
• 204 NO CONTENT – [DELETE]
• 400 BAD REQUEST – [*]
• 404 NOT FOUND – [*]
• 500 INTERNAL SERVER ERROR – [*]
Expected URI & Responses
• GET /collection : Return list of resources
• GET /collection/resourceId: Return a resource
• POST /collection : Create resource, return Id
• PUT /collection/resourceId : Update resource
• DELETE /collection/resource : Return empty
body
• PATCH /collection/resource : Return updated
resource
State REL links - HATEOAS
{
// fields …
“links” : {
“self” : {
“href” : http://api.project.company.org/departments/1/employee/100
},
“parent” : {
“href” : http://api.project.company.org/departments/1
},
“outOfOffice” : { // Out of office state change
“href” :
http://api.project.company.org/departments/1/employee/100/outOfOffice
“method”:”POST”
},
}
}
HATEOAS
• Hypermedia as the engine of state
• Decouples client and server. No hard coded
URIs in client
• REST service controls state transitions through
available links
• Available Open Source libraries to generate
links
Pagination
• Use filter query parameters &page=1
• Normal GET resource must not use query
parameters
• Filter on start, end page and page size
• Returned HATEOAS links must define href links
with rel elements for = “next”,
“previous”,”first” and “last”
REST Rules
• Separator (/) indicates a hierarchy relationship
• Trailing slash (/) must not be included in URIs
• Singular noun for document names
• Plural noun for collection and store names
• Verb or verb phrase for controller names
• Exclude file extensions in URIs (no .xml etc)
• CRUD function names should not be used in
URIs; not /deleteUser/1234 but /user/1234

More Related Content

What's hot

Working with Portlets in ADF and Webcenter
Working with Portlets in ADF and WebcenterWorking with Portlets in ADF and Webcenter
Working with Portlets in ADF and Webcenter
DataNext Solutions
 
Rails on HBase
Rails on HBaseRails on HBase
Rails on HBase
zpinter
 

What's hot (20)

Office 365 Groups and Tasks API - Getting Started
Office 365 Groups and Tasks API - Getting StartedOffice 365 Groups and Tasks API - Getting Started
Office 365 Groups and Tasks API - Getting Started
 
Building No-Code Collaboration Solutions on Office 365
Building No-Code Collaboration Solutions on Office 365Building No-Code Collaboration Solutions on Office 365
Building No-Code Collaboration Solutions on Office 365
 
Best Practices to SharePoint Architecture Fundamentals NZ & AUS
Best Practices to SharePoint Architecture Fundamentals NZ & AUSBest Practices to SharePoint Architecture Fundamentals NZ & AUS
Best Practices to SharePoint Architecture Fundamentals NZ & AUS
 
Chef - managing yours servers with Code
Chef - managing yours servers with CodeChef - managing yours servers with Code
Chef - managing yours servers with Code
 
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
Part I: SharePoint 2013 Administration by Todd Klindt and Shane Young - SPTec...
 
5 Reasons Your Site Needs Acquia Search
5 Reasons Your Site Needs Acquia Search5 Reasons Your Site Needs Acquia Search
5 Reasons Your Site Needs Acquia Search
 
Plan, prepare & overall process of upgrade and migrate to SharePoint 2013
Plan, prepare & overall process of upgrade and migrate to SharePoint 2013Plan, prepare & overall process of upgrade and migrate to SharePoint 2013
Plan, prepare & overall process of upgrade and migrate to SharePoint 2013
 
Kafka api
Kafka apiKafka api
Kafka api
 
Using power shell to improve sharepoint management
Using power shell to improve sharepoint managementUsing power shell to improve sharepoint management
Using power shell to improve sharepoint management
 
Working with Portlets in ADF and Webcenter
Working with Portlets in ADF and WebcenterWorking with Portlets in ADF and Webcenter
Working with Portlets in ADF and Webcenter
 
Talking Services with Oracle ADF and Oracle SOA Suite
Talking Services with Oracle ADF and Oracle SOA SuiteTalking Services with Oracle ADF and Oracle SOA Suite
Talking Services with Oracle ADF and Oracle SOA Suite
 
Rails on HBase
Rails on HBaseRails on HBase
Rails on HBase
 
SharePoint Development (Lesson 3)
SharePoint Development (Lesson 3)SharePoint Development (Lesson 3)
SharePoint Development (Lesson 3)
 
OmniUpdate User Training Conference 2014: Our "Special Sauce" Responsive Desi...
OmniUpdate User Training Conference 2014: Our "Special Sauce" Responsive Desi...OmniUpdate User Training Conference 2014: Our "Special Sauce" Responsive Desi...
OmniUpdate User Training Conference 2014: Our "Special Sauce" Responsive Desi...
 
SharePoint On-Premises Nirvana
SharePoint On-Premises NirvanaSharePoint On-Premises Nirvana
SharePoint On-Premises Nirvana
 
Architectural changes in SharePoint 2013
Architectural changes in SharePoint 2013Architectural changes in SharePoint 2013
Architectural changes in SharePoint 2013
 
Set up an SharePoint On-Premises environment for developing provider-hosted a...
Set up an SharePoint On-Premises environment for developing provider-hosted a...Set up an SharePoint On-Premises environment for developing provider-hosted a...
Set up an SharePoint On-Premises environment for developing provider-hosted a...
 
Infrastructure Best Practices for SharePoint On-Premises presented by Michael...
Infrastructure Best Practices for SharePoint On-Premises presented by Michael...Infrastructure Best Practices for SharePoint On-Premises presented by Michael...
Infrastructure Best Practices for SharePoint On-Premises presented by Michael...
 
Automating SQL Server Database Creation for SharePoint
Automating SQL Server Database Creation for SharePointAutomating SQL Server Database Creation for SharePoint
Automating SQL Server Database Creation for SharePoint
 
SharePoint Saturday The Conference 2011 - SP2010 Performance
SharePoint Saturday The Conference 2011 - SP2010 PerformanceSharePoint Saturday The Conference 2011 - SP2010 Performance
SharePoint Saturday The Conference 2011 - SP2010 Performance
 

Viewers also liked

الدعامة والحركة أحياء الثانوية العامة 2016
الدعامة والحركة أحياء الثانوية العامة 2016الدعامة والحركة أحياء الثانوية العامة 2016
الدعامة والحركة أحياء الثانوية العامة 2016
Abdallah Omar
 
Fintzen 2Q12 Capacity
Fintzen 2Q12 CapacityFintzen 2Q12 Capacity
Fintzen 2Q12 Capacity
Nicholas Haan
 
Lerning outcomecontent
Lerning outcomecontentLerning outcomecontent
Lerning outcomecontent
phele1994
 

Viewers also liked (20)

การเขียนกรณีศึกษา.pptx
การเขียนกรณีศึกษา.pptxการเขียนกรณีศึกษา.pptx
การเขียนกรณีศึกษา.pptx
 
الدعامة والحركة أحياء الثانوية العامة 2016
الدعامة والحركة أحياء الثانوية العامة 2016الدعامة والحركة أحياء الثانوية العامة 2016
الدعامة والحركة أحياء الثانوية العامة 2016
 
trip to Thailand
trip to Thailandtrip to Thailand
trip to Thailand
 
Article research
Article researchArticle research
Article research
 
My WWE Top 15 Matches of the Year 2014
My WWE Top 15 Matches of the Year 2014My WWE Top 15 Matches of the Year 2014
My WWE Top 15 Matches of the Year 2014
 
How to Break Through the Glass Ceiling
How to Break Through the Glass CeilingHow to Break Through the Glass Ceiling
How to Break Through the Glass Ceiling
 
η ρωσικη επανασταση
η ρωσικη επαναστασηη ρωσικη επανασταση
η ρωσικη επανασταση
 
Tempo de maturidade nov 2014
Tempo de maturidade   nov 2014 Tempo de maturidade   nov 2014
Tempo de maturidade nov 2014
 
JW Future of Search
JW Future of SearchJW Future of Search
JW Future of Search
 
العنوان وسميوطيقا الاتصال الأدبي| محمد فكري الجزار
العنوان وسميوطيقا الاتصال الأدبي| محمد فكري الجزارالعنوان وسميوطيقا الاتصال الأدبي| محمد فكري الجزار
العنوان وسميوطيقا الاتصال الأدبي| محمد فكري الجزار
 
Fintzen 2Q12 Capacity
Fintzen 2Q12 CapacityFintzen 2Q12 Capacity
Fintzen 2Q12 Capacity
 
Не е ли вече време.....
Не е ли вече време.....Не е ли вече време.....
Не е ли вече време.....
 
Bora stankovic kostana
Bora stankovic   kostanaBora stankovic   kostana
Bora stankovic kostana
 
Film magazine analysis
Film magazine analysisFilm magazine analysis
Film magazine analysis
 
Social media followers & how to engage them
Social media followers & how to engage themSocial media followers & how to engage them
Social media followers & how to engage them
 
Ute otras variables que determinan la diversidad en el aula
Ute otras variables que determinan la diversidad en el aulaUte otras variables que determinan la diversidad en el aula
Ute otras variables que determinan la diversidad en el aula
 
Kemiskinan september 2014
Kemiskinan september 2014Kemiskinan september 2014
Kemiskinan september 2014
 
Proc.legis
Proc.legisProc.legis
Proc.legis
 
Lerning outcomecontent
Lerning outcomecontentLerning outcomecontent
Lerning outcomecontent
 
BAFF SUV 2
BAFF SUV 2BAFF SUV 2
BAFF SUV 2
 

Similar to RestfulDesignRules

JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
Shreedhar Ganapathy
 

Similar to RestfulDesignRules (20)

Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML Resources
 
RESTful HATEOAS standards using Java based Katharsis
RESTful HATEOAS standards using Java based KatharsisRESTful HATEOAS standards using Java based Katharsis
RESTful HATEOAS standards using Java based Katharsis
 
RESTful HATEOAS standards using Java based Katharsis
RESTful HATEOAS standards using Java based KatharsisRESTful HATEOAS standards using Java based Katharsis
RESTful HATEOAS standards using Java based Katharsis
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
 
Rest in practice
Rest in practiceRest in practice
Rest in practice
 
RESTful for opentravel.org by HP
RESTful for opentravel.org by HPRESTful for opentravel.org by HP
RESTful for opentravel.org by HP
 
FHIR REST API
FHIR REST APIFHIR REST API
FHIR REST API
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
RESTful Web Service using Swagger
RESTful Web Service using SwaggerRESTful Web Service using Swagger
RESTful Web Service using Swagger
 
At Begin, URL Handling and REST
At Begin, URL Handling and RESTAt Begin, URL Handling and REST
At Begin, URL Handling and REST
 
Леонід Кузьмін “Сам собі паблішер. Від сайту ігрової студії до універсального...
Леонід Кузьмін “Сам собі паблішер. Від сайту ігрової студії до універсального...Леонід Кузьмін “Сам собі паблішер. Від сайту ігрової студії до універсального...
Леонід Кузьмін “Сам собі паблішер. Від сайту ігрової студії до універсального...
 
The never-ending REST API design debate
The never-ending REST API design debateThe never-ending REST API design debate
The never-ending REST API design debate
 
Introduction to Google APIs
Introduction to Google APIsIntroduction to Google APIs
Introduction to Google APIs
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011JAX-RS JavaOne Hyderabad, India 2011
JAX-RS JavaOne Hyderabad, India 2011
 
Attacking REST API
Attacking REST APIAttacking REST API
Attacking REST API
 
Getting started with DSpace 7 REST API
Getting started with DSpace 7 REST APIGetting started with DSpace 7 REST API
Getting started with DSpace 7 REST API
 
Introduction to Restful Web Services
Introduction to Restful Web ServicesIntroduction to Restful Web Services
Introduction to Restful Web Services
 

RestfulDesignRules

  • 2. Why? – adds value • Encourages a Contract-First API service • Rules help design for scalable services • Establishes a design standard and language • Rules promotes a “crisp”API making happy clients, reducing Support costs and sells the API (Netflix, Google, Github) • Sources : Apache project, Roy Fielding thesis • “Rest API Design Rule Book” - Mark Masse (O'Reilly Pub)
  • 3. Web Architecture Scalability Constraints • Client-Server: must play distinct roles • Uniform Interface: standard interaction between client and server components • Cache : reduce latency, improve availability. Client or server • Stateless: resource at server has no state. Only client has conversational state
  • 4. Uniform Interface • Identify service resources with an address: URI • Resource representation – resource returns different representations to different clients • Self descriptive – desired resource state reflected in request and current state in response. An update is successful or not • Links(HATEOAS) – current state defines links to related allowed links, may depend on client
  • 5. Questions • How do I design for self-descriptive messages? • REST models state – how do I model this? • What URI name shall I use for CRUD services? • What URI name shall I use for non-CRUD services? • What HTTP response status codes to use for use cases?
  • 6. REST Modeling • HTTP methods for CRUD or non-CRUD services • Document/Resource – object, record : animal • Collection resource – many related objects: animals (=database) • Store resource – many unrelated documents • Controller resource – process resource • Idempotent – side affect free • URI path – hierarchy of resources; /cats/felix
  • 7. HTTP Method-Service Map • GET(SELECT) – Retrieve document(s) • POST(CREATE) – Create a new resource in a collection • POST(PROCESS) – Perform non-CRUD process • PUT(UPDATE) – Update resource • DELETE(DELETE) – Delete resource • PATCH(UPDATE) – Update with changes • HEAD – Get metadata or “ping” resource • OPTIONS – Get resource’s “Allowed” URI links
  • 8. Recommended Status Codes • 200 OK – [GET] • 201 CREATED – [POST/PUT/PATCH] • 202 ACCEPTED – [POST], async action • 204 NO CONTENT – [DELETE] • 400 BAD REQUEST – [*] • 404 NOT FOUND – [*] • 500 INTERNAL SERVER ERROR – [*]
  • 9. Expected URI & Responses • GET /collection : Return list of resources • GET /collection/resourceId: Return a resource • POST /collection : Create resource, return Id • PUT /collection/resourceId : Update resource • DELETE /collection/resource : Return empty body • PATCH /collection/resource : Return updated resource
  • 10. State REL links - HATEOAS { // fields … “links” : { “self” : { “href” : http://api.project.company.org/departments/1/employee/100 }, “parent” : { “href” : http://api.project.company.org/departments/1 }, “outOfOffice” : { // Out of office state change “href” : http://api.project.company.org/departments/1/employee/100/outOfOffice “method”:”POST” }, } }
  • 11. HATEOAS • Hypermedia as the engine of state • Decouples client and server. No hard coded URIs in client • REST service controls state transitions through available links • Available Open Source libraries to generate links
  • 12. Pagination • Use filter query parameters &page=1 • Normal GET resource must not use query parameters • Filter on start, end page and page size • Returned HATEOAS links must define href links with rel elements for = “next”, “previous”,”first” and “last”
  • 13. REST Rules • Separator (/) indicates a hierarchy relationship • Trailing slash (/) must not be included in URIs • Singular noun for document names • Plural noun for collection and store names • Verb or verb phrase for controller names • Exclude file extensions in URIs (no .xml etc) • CRUD function names should not be used in URIs; not /deleteUser/1234 but /user/1234