SlideShare a Scribd company logo
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

PDF
Kako pravilno konfigurisati SharePoint on-premises za SharePoint Add-ins (Sha...
PPTX
Rev Your Engines: SharePoint Performance Best Practices
PDF
(Almost) All About Apps for SharePoint 2013
PDF
Better Search UX
PPTX
Rev Your Engines - SharePoint Performance Best Practices
PDF
ECS19 - Laura Kokkarinen - Everything you need to know about SharePoint site ...
PDF
Implementing Site Search in CQ5 / AEM
PPTX
Deep Dive into the Content Query Web Part by Christina Wheeler - SPTechCon
Kako pravilno konfigurisati SharePoint on-premises za SharePoint Add-ins (Sha...
Rev Your Engines: SharePoint Performance Best Practices
(Almost) All About Apps for SharePoint 2013
Better Search UX
Rev Your Engines - SharePoint Performance Best Practices
ECS19 - Laura Kokkarinen - Everything you need to know about SharePoint site ...
Implementing Site Search in CQ5 / AEM
Deep Dive into the Content Query Web Part by Christina Wheeler - SPTechCon

What's hot (20)

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

Viewers also liked (20)

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

Similar to RestfulDesignRules (20)

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

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