SlideShare a Scribd company logo
1 of 19
CREATING TRULY RESTFUL APIS
BY @DOMENIC
A STORY IN THREE PARTS




1. URLs = Resources; Verbs = Actions
2. Using the HTTP Machinery
3. Linking
URLS = RESOURCES; VERBS = ACTIONS
RESOURCE ARCHETYPES: DOCUMENT

   Think “object instance” or “database record.”
   Examples:
       /partnerships/1234
       /partnerships/1234/funds/ABCD
       /users/0987
       /users/0987/settings
   Typical verbs:
       GET — retrieves the document
       DELETE — deletes the document
       PATCH — performs a partial update of the document
       PUT — creates or updates the document (see upcoming slides)
   Documents can be organized into either collections or stores
RESOURCE ARCHETYPES: COLLECTION

 A server-managed resource directory
 Clients may propose addition to the directory, but the server decides the result
 Examples:
      /partnerships
      /partnerships/1234/funds
      /users
 Typical verbs:
      GET /collection — a listing of the whole collection, either inline or as links
      POST /collection — creates a new document, and returns you a link to it
      PUT /collection/document — replaces an existing document
      GET, PATCH, DELETE /collection/document
RESOURCE ARCHETYPES: STORE

 A client-managed resource repository
 Examples:
      /users/0987/favorite-funds
      /partnerships/1234/metadata
 Documents exist under stores:
      /users/0987/favorite-funds/ABCD
      /partnerships/1234/metadata/investment-preferences
 Typical verbs:
      GET /store — a listing of the whole store, either inline or as links
      PUT /store/document — creates or replaces the document
      GET, PATCH, DELETE /store/document
DOMAIN MODELING WITH RESOURCES

 URLs are always nouns, never actions:
      Find distance between points: GET /distance?point1=x&point2=y
      Discount this item’s price by 15%:
          PUT /item/discount { percent: 15 }
          or PUT /discounts/itemID { percent: 15 } if discounts are a primary entity in your domain

 Hierarchical URL structure represents hierarchy of resources in your domain
      Not just stores and collections: /user/0987/settings; /user/0987/pictures/large; etc.
 Query parameters represent filtering, sorting, and projections
 Extra verbs:
      HEAD lets you interrogate for certain metadata, e.g. Content-Length
      OPTIONS lets you find out what verbs are supported, e.g. “is this document deletable?”
USING THE HTTP MACHINERY
STATUS CODES: THE BASICS


 There’s life beyond 200, 404, and 500!


  100, 101 = meta stuff; don’t worry about it
  2xx = success
  3xx = redirection: further action may be needed
  4xx = client error: user screwed up
  5xx = server error: server screwed up




http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
SAMPLE SIMPLE STATUS CODE USES: GET AND DELETE

 GET /partnerships/1234/funds/ABCD
     200 OK
     301 Moved Permanently: the fund has been transferred to another partnership
     401 Unauthorized: you need to authenticate first
     403 Forbidden: you’re authenticated, but not authorized
     404 Not Found: no such fund exists under this partnership
 DELETE /document
     204 No Content
SAMPLE SIMPLE STATUS CODE USES: PUT AND POST

   PUT /store/document
       200 OK: old document overwritten
       201 Created: new document created
       409 Conflict: you tried to overwrite the document but you didn’t have the latest version
   POST /collection
       201 Created: new document created
       303 See Other: a document with that name (or whatever) already existed
   Either case:
       400 Bad Request: data did not pass validation
       401, 403: as before
       413 Request Entity Too Large: you tried to upload too large of a document
       415 Unsupported Media Type: you tried to upload a PDF, but we only support text files
OTHER IMPORTANT MACHINERY

 Caching
      Client-side caching via Cache-Control and Expires headers
      Conditional GETs to avoid downloading again
 Conditional updates to avoid conflicts
 Content negotiation to serve the correct representation of a resource
 Range requests for downloading chunks from a larger document
 Metadata headers: Content-Type, Content-Length, Etag, …
 Authorization header


Takeaway: no need to build envelopes or protocols on top of HTTP; it has the tools you need
LINKING
HYPERTEXT AS THE ENGINE OF APPLICATION STATE

 Your API should advertise a single entry point, e.g. https://api.lab49.com
 From there, links direct you to desired resources
 Links are specified by relationship types, or rels.
      There are standard rels, e.g. prev, next, parent, self, etc.
      But most relationships are domain-specific, telling you how to get to an interesting resource
 Clients do not know resource URLs
      They know the single entry point URL
      They know the rels of resources they are interested in
      They know how to navigate from resource to resource
EXAMPLE: GET /



{
    "_links": {
        "http://rels.api.lab49.com/partnerships": { "href": "/partnerships" },
        "http://rels.api.lab49.com/users": { "href": "/users" }
    }
}
EXAMPLE: GET /PARTNERSHIPS

{
    "_links": {
        "http://rels.api.lab49.com/partnership": [
            { "href": "/partnerships/1234" },
            { "href": "/partnerships/4321" },
            { "href": "/partnerships/3142" }
        ]
    }
}
EXAMPLE: GET /PARTNERSHIPS/1234


{
    "_links": {
     "http://rels.api.lab49.com/funds": { "href": "/partnerships/1234/funds" }
    },
    "name": "Denicola Global Management",
    "type": "GP",
    "missionStatement": "To make lots of money"
}
WRAP-UP
THINGS WE DON’T HAVE TIME FOR


 Controller resources
 Embedded resources
 API versioning schemes
 Authentication, e.g. with OAuth 2
 Data formats, e.g. how to format PATCH data or hypermedia links
 Playing nice with proxies
 HTTPbis

More Related Content

What's hot

What's hot (20)

Kafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and GrafanaKafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and Grafana
 
PLAT-13 Metadata Extraction and Transformation
PLAT-13 Metadata Extraction and TransformationPLAT-13 Metadata Extraction and Transformation
PLAT-13 Metadata Extraction and Transformation
 
Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링
 
Walking Through Spring Cloud Data Flow
Walking Through Spring Cloud Data FlowWalking Through Spring Cloud Data Flow
Walking Through Spring Cloud Data Flow
 
An overview of the Eventuate Platform
An overview of the Eventuate PlatformAn overview of the Eventuate Platform
An overview of the Eventuate Platform
 
Ibm Optim Techical Overview 01282009
Ibm Optim Techical Overview 01282009Ibm Optim Techical Overview 01282009
Ibm Optim Techical Overview 01282009
 
Apache Airflow Introduction
Apache Airflow IntroductionApache Airflow Introduction
Apache Airflow Introduction
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
 
How to deploy PHP projects with docker
How to deploy PHP projects with dockerHow to deploy PHP projects with docker
How to deploy PHP projects with docker
 
Welcome to the Flink Community!
Welcome to the Flink Community!Welcome to the Flink Community!
Welcome to the Flink Community!
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
AWS Neptune - A Fast and reliable Graph Database Built for the Cloud
AWS Neptune - A Fast and reliable Graph Database Built for the CloudAWS Neptune - A Fast and reliable Graph Database Built for the Cloud
AWS Neptune - A Fast and reliable Graph Database Built for the Cloud
 
Architectural changes in the repo in 6.1 and beyond
Architectural changes in the repo in 6.1 and beyondArchitectural changes in the repo in 6.1 and beyond
Architectural changes in the repo in 6.1 and beyond
 
Azure data factory V1 and V2
Azure data factory V1 and V2Azure data factory V1 and V2
Azure data factory V1 and V2
 
(Re)Indexing Large Repositories in Alfresco
(Re)Indexing Large Repositories in Alfresco(Re)Indexing Large Repositories in Alfresco
(Re)Indexing Large Repositories in Alfresco
 
Deploying Flink on Kubernetes - David Anderson
 Deploying Flink on Kubernetes - David Anderson Deploying Flink on Kubernetes - David Anderson
Deploying Flink on Kubernetes - David Anderson
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Disaster Recovery Synapse
Disaster Recovery SynapseDisaster Recovery Synapse
Disaster Recovery Synapse
 
실시간 이상탐지를 위한 머신러닝 모델에 Druid _ Imply 활용하기
실시간 이상탐지를 위한 머신러닝 모델에 Druid _ Imply 활용하기실시간 이상탐지를 위한 머신러닝 모델에 Druid _ Imply 활용하기
실시간 이상탐지를 위한 머신러닝 모델에 Druid _ Imply 활용하기
 
Screw DevOps, Let's Talk DataOps
Screw DevOps, Let's Talk DataOpsScrew DevOps, Let's Talk DataOps
Screw DevOps, Let's Talk DataOps
 

Viewers also liked

The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
Domenic Denicola
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Solution4Future
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
Domenic Denicola
 

Viewers also liked (20)

Hypermedia APIs - GeekOut
Hypermedia APIs - GeekOutHypermedia APIs - GeekOut
Hypermedia APIs - GeekOut
 
JahiaOne - Jahia7 New REST API
JahiaOne - Jahia7 New REST APIJahiaOne - Jahia7 New REST API
JahiaOne - Jahia7 New REST API
 
Real World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScriptReal World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScript
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
 
Client-Side Packages
Client-Side PackagesClient-Side Packages
Client-Side Packages
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
Async Frontiers
Async FrontiersAsync Frontiers
Async Frontiers
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Domains!
Domains!Domains!
Domains!
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
The jsdom
The jsdomThe jsdom
The jsdom
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
SharePoint 2013 Client-Side Rendering (CSR) & JSLink Templates
SharePoint 2013 Client-Side Rendering (CSR) & JSLink TemplatesSharePoint 2013 Client-Side Rendering (CSR) & JSLink Templates
SharePoint 2013 Client-Side Rendering (CSR) & JSLink Templates
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 

Similar to Creating Truly RESTful APIs

Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
Carol McDonald
 

Similar to Creating Truly RESTful APIs (20)

RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Rest
RestRest
Rest
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Resilient Linked Data
Resilient Linked DataResilient Linked Data
Resilient Linked Data
 
DataCite How To: Use the MDS
DataCite How To: Use the MDSDataCite How To: Use the MDS
DataCite How To: Use the MDS
 
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.
 
Crossref XML and tools for small publishers (EASE Conference 2018)
Crossref XML and tools for small publishers (EASE Conference 2018)Crossref XML and tools for small publishers (EASE Conference 2018)
Crossref XML and tools for small publishers (EASE Conference 2018)
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
CrossRef How-to: A Technical Introduction to the Basics of CrossRef, Chuck Ko...
CrossRef How-to: A Technical Introduction to the Basics of CrossRef, Chuck Ko...CrossRef How-to: A Technical Introduction to the Basics of CrossRef, Chuck Ko...
CrossRef How-to: A Technical Introduction to the Basics of CrossRef, Chuck Ko...
 
Api best practices
Api best practicesApi best practices
Api best practices
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and example
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and example
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
Routes Controllers
Routes ControllersRoutes Controllers
Routes Controllers
 
WebAppSec Updates from W3C
WebAppSec Updates from W3CWebAppSec Updates from W3C
WebAppSec Updates from W3C
 

More from Domenic Denicola

How to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards BodiesHow to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards Bodies
Domenic Denicola
 

More from Domenic Denicola (10)

ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
Streams for the Web
Streams for the WebStreams for the Web
Streams for the Web
 
After Return of the Jedi
After Return of the JediAfter Return of the Jedi
After Return of the Jedi
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
How to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards BodiesHow to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards Bodies
 
The Extensible Web
The Extensible WebThe Extensible Web
The Extensible Web
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great Justice
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 

Recently uploaded

Recently uploaded (20)

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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Creating Truly RESTful APIs

  • 1. CREATING TRULY RESTFUL APIS BY @DOMENIC
  • 2. A STORY IN THREE PARTS 1. URLs = Resources; Verbs = Actions 2. Using the HTTP Machinery 3. Linking
  • 3. URLS = RESOURCES; VERBS = ACTIONS
  • 4. RESOURCE ARCHETYPES: DOCUMENT  Think “object instance” or “database record.”  Examples:  /partnerships/1234  /partnerships/1234/funds/ABCD  /users/0987  /users/0987/settings  Typical verbs:  GET — retrieves the document  DELETE — deletes the document  PATCH — performs a partial update of the document  PUT — creates or updates the document (see upcoming slides)  Documents can be organized into either collections or stores
  • 5. RESOURCE ARCHETYPES: COLLECTION  A server-managed resource directory  Clients may propose addition to the directory, but the server decides the result  Examples:  /partnerships  /partnerships/1234/funds  /users  Typical verbs:  GET /collection — a listing of the whole collection, either inline or as links  POST /collection — creates a new document, and returns you a link to it  PUT /collection/document — replaces an existing document  GET, PATCH, DELETE /collection/document
  • 6. RESOURCE ARCHETYPES: STORE  A client-managed resource repository  Examples:  /users/0987/favorite-funds  /partnerships/1234/metadata  Documents exist under stores:  /users/0987/favorite-funds/ABCD  /partnerships/1234/metadata/investment-preferences  Typical verbs:  GET /store — a listing of the whole store, either inline or as links  PUT /store/document — creates or replaces the document  GET, PATCH, DELETE /store/document
  • 7. DOMAIN MODELING WITH RESOURCES  URLs are always nouns, never actions:  Find distance between points: GET /distance?point1=x&point2=y  Discount this item’s price by 15%:  PUT /item/discount { percent: 15 }  or PUT /discounts/itemID { percent: 15 } if discounts are a primary entity in your domain  Hierarchical URL structure represents hierarchy of resources in your domain  Not just stores and collections: /user/0987/settings; /user/0987/pictures/large; etc.  Query parameters represent filtering, sorting, and projections  Extra verbs:  HEAD lets you interrogate for certain metadata, e.g. Content-Length  OPTIONS lets you find out what verbs are supported, e.g. “is this document deletable?”
  • 8. USING THE HTTP MACHINERY
  • 9. STATUS CODES: THE BASICS There’s life beyond 200, 404, and 500!  100, 101 = meta stuff; don’t worry about it  2xx = success  3xx = redirection: further action may be needed  4xx = client error: user screwed up  5xx = server error: server screwed up http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  • 10. SAMPLE SIMPLE STATUS CODE USES: GET AND DELETE  GET /partnerships/1234/funds/ABCD  200 OK  301 Moved Permanently: the fund has been transferred to another partnership  401 Unauthorized: you need to authenticate first  403 Forbidden: you’re authenticated, but not authorized  404 Not Found: no such fund exists under this partnership  DELETE /document  204 No Content
  • 11. SAMPLE SIMPLE STATUS CODE USES: PUT AND POST  PUT /store/document  200 OK: old document overwritten  201 Created: new document created  409 Conflict: you tried to overwrite the document but you didn’t have the latest version  POST /collection  201 Created: new document created  303 See Other: a document with that name (or whatever) already existed  Either case:  400 Bad Request: data did not pass validation  401, 403: as before  413 Request Entity Too Large: you tried to upload too large of a document  415 Unsupported Media Type: you tried to upload a PDF, but we only support text files
  • 12. OTHER IMPORTANT MACHINERY  Caching  Client-side caching via Cache-Control and Expires headers  Conditional GETs to avoid downloading again  Conditional updates to avoid conflicts  Content negotiation to serve the correct representation of a resource  Range requests for downloading chunks from a larger document  Metadata headers: Content-Type, Content-Length, Etag, …  Authorization header Takeaway: no need to build envelopes or protocols on top of HTTP; it has the tools you need
  • 14. HYPERTEXT AS THE ENGINE OF APPLICATION STATE  Your API should advertise a single entry point, e.g. https://api.lab49.com  From there, links direct you to desired resources  Links are specified by relationship types, or rels.  There are standard rels, e.g. prev, next, parent, self, etc.  But most relationships are domain-specific, telling you how to get to an interesting resource  Clients do not know resource URLs  They know the single entry point URL  They know the rels of resources they are interested in  They know how to navigate from resource to resource
  • 15. EXAMPLE: GET / { "_links": { "http://rels.api.lab49.com/partnerships": { "href": "/partnerships" }, "http://rels.api.lab49.com/users": { "href": "/users" } } }
  • 16. EXAMPLE: GET /PARTNERSHIPS { "_links": { "http://rels.api.lab49.com/partnership": [ { "href": "/partnerships/1234" }, { "href": "/partnerships/4321" }, { "href": "/partnerships/3142" } ] } }
  • 17. EXAMPLE: GET /PARTNERSHIPS/1234 { "_links": { "http://rels.api.lab49.com/funds": { "href": "/partnerships/1234/funds" } }, "name": "Denicola Global Management", "type": "GP", "missionStatement": "To make lots of money" }
  • 19. THINGS WE DON’T HAVE TIME FOR  Controller resources  Embedded resources  API versioning schemes  Authentication, e.g. with OAuth 2  Data formats, e.g. how to format PATCH data or hypermedia links  Playing nice with proxies  HTTPbis
  • 20. THINGS YOU SHOULD READ  HTTPbis: Semantics and Content (and the others)  RESTful Web Services Cookbook by Subbu Allamaraju  REST API Design Rulebook by Mark Masse  Hypertext Application Language (HAL) spec

Editor's Notes

  1. A RESTful API is an HTTP API, where a client sends requests at a server and gets responsesIt’s very much so the correct way to design HTTP APIs, which takes advantage of the features of the platform instead of trying to shoehorn e.g. RPC into the web