SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialAdonisDamian
 
Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...
Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...
Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...Amazon Web Services
 
HR Strategy Guide.pdf
HR Strategy Guide.pdfHR Strategy Guide.pdf
HR Strategy Guide.pdfNAVASIIA
 
Talent Advisor defined
Talent Advisor definedTalent Advisor defined
Talent Advisor definedRob McIntosh
 
Human Resource Planning Process PowerPoint Presentation Slides
Human Resource Planning Process PowerPoint Presentation SlidesHuman Resource Planning Process PowerPoint Presentation Slides
Human Resource Planning Process PowerPoint Presentation SlidesSlideTeam
 
Human Resources Business Capability Model
Human Resources Business Capability Model Human Resources Business Capability Model
Human Resources Business Capability Model CIOPages
 
Employee engagement survey
Employee engagement surveyEmployee engagement survey
Employee engagement surveypoojametiom
 
Human Resource Management
Human Resource ManagementHuman Resource Management
Human Resource ManagementSanjay Rajpoot
 
Get Savvy with Snowflake
Get Savvy with SnowflakeGet Savvy with Snowflake
Get Savvy with SnowflakeMatillion
 
Building a Multi-tenanted SaaS with Node.js
Building a Multi-tenanted SaaS with Node.jsBuilding a Multi-tenanted SaaS with Node.js
Building a Multi-tenanted SaaS with Node.jsEoin Shanaghy
 
Developing an HR Strategy
Developing an HR Strategy Developing an HR Strategy
Developing an HR Strategy Niladri Roy
 
Hr business partner kpi
Hr business partner kpiHr business partner kpi
Hr business partner kpizewfurita
 
Talent Acquisition Best Practices Process Map
Talent Acquisition Best Practices Process MapTalent Acquisition Best Practices Process Map
Talent Acquisition Best Practices Process Mapblayton551
 
6 Essential HR Trends in 2024 for Organization Growth
6 Essential HR Trends in 2024 for Organization Growth6 Essential HR Trends in 2024 for Organization Growth
6 Essential HR Trends in 2024 for Organization GrowthKeziyaRajan
 
How to design and implement a data ops architecture with sdc and gcp
How to design and implement a data ops architecture with sdc and gcpHow to design and implement a data ops architecture with sdc and gcp
How to design and implement a data ops architecture with sdc and gcpJoseph Arriola
 
The role of People Analytics in recruiting
The role of People Analytics in recruitingThe role of People Analytics in recruiting
The role of People Analytics in recruitingDavid Green
 
IMPACT OF ATTRITION IN BPO SECTOR
IMPACT OF ATTRITION IN BPO SECTORIMPACT OF ATTRITION IN BPO SECTOR
IMPACT OF ATTRITION IN BPO SECTORApurba Lahiri
 

La actualidad más candente (20)

Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
 
Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...
Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...
Next generation intelligent data lakes, powered by GraphQL & AWS AppSync - MA...
 
HR Strategy Guide.pdf
HR Strategy Guide.pdfHR Strategy Guide.pdf
HR Strategy Guide.pdf
 
Talent Advisor defined
Talent Advisor definedTalent Advisor defined
Talent Advisor defined
 
Human Resource Planning Process PowerPoint Presentation Slides
Human Resource Planning Process PowerPoint Presentation SlidesHuman Resource Planning Process PowerPoint Presentation Slides
Human Resource Planning Process PowerPoint Presentation Slides
 
Human Resources Business Capability Model
Human Resources Business Capability Model Human Resources Business Capability Model
Human Resources Business Capability Model
 
Employee engagement survey
Employee engagement surveyEmployee engagement survey
Employee engagement survey
 
Human Resource Management
Human Resource ManagementHuman Resource Management
Human Resource Management
 
Get Savvy with Snowflake
Get Savvy with SnowflakeGet Savvy with Snowflake
Get Savvy with Snowflake
 
Hr roi
Hr roiHr roi
Hr roi
 
Building a Multi-tenanted SaaS with Node.js
Building a Multi-tenanted SaaS with Node.jsBuilding a Multi-tenanted SaaS with Node.js
Building a Multi-tenanted SaaS with Node.js
 
Developing an HR Strategy
Developing an HR Strategy Developing an HR Strategy
Developing an HR Strategy
 
Hr business partner kpi
Hr business partner kpiHr business partner kpi
Hr business partner kpi
 
Talent Acquisition Best Practices Process Map
Talent Acquisition Best Practices Process MapTalent Acquisition Best Practices Process Map
Talent Acquisition Best Practices Process Map
 
6 Essential HR Trends in 2024 for Organization Growth
6 Essential HR Trends in 2024 for Organization Growth6 Essential HR Trends in 2024 for Organization Growth
6 Essential HR Trends in 2024 for Organization Growth
 
How to design and implement a data ops architecture with sdc and gcp
How to design and implement a data ops architecture with sdc and gcpHow to design and implement a data ops architecture with sdc and gcp
How to design and implement a data ops architecture with sdc and gcp
 
The role of People Analytics in recruiting
The role of People Analytics in recruitingThe role of People Analytics in recruiting
The role of People Analytics in recruiting
 
IMPACT OF ATTRITION IN BPO SECTOR
IMPACT OF ATTRITION IN BPO SECTORIMPACT OF ATTRITION IN BPO SECTOR
IMPACT OF ATTRITION IN BPO SECTOR
 
Screw DevOps, Let's Talk DataOps
Screw DevOps, Let's Talk DataOpsScrew DevOps, Let's Talk DataOps
Screw DevOps, Let's Talk DataOps
 
HRBP Presentation v4
HRBP Presentation v4HRBP Presentation v4
HRBP Presentation v4
 

Destacado

Hypermedia APIs - GeekOut
Hypermedia APIs - GeekOutHypermedia APIs - GeekOut
Hypermedia APIs - GeekOutJan Kronquist
 
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 JavaScriptDomenic Denicola
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was BornDomenic Denicola
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation JavascriptRamesh Nair
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptWojciech Dzikowski
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overviewhesher
 
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 TemplatesMuawiyah Shannak
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)Domenic Denicola
 

Destacado (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 a Creating Truly RESTful APIs

RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
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.jsCarol McDonald
 
Resilient Linked Data
Resilient Linked DataResilient Linked Data
Resilient Linked DataDave Reynolds
 
DataCite How To: Use the MDS
DataCite How To: Use the MDSDataCite How To: Use the MDS
DataCite How To: Use the MDSFrauke Ziedorn
 
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.Mario Cardinal
 
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)Crossref
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
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...Crossref
 
Api best practices
Api best practicesApi best practices
Api best practicesRobert Lee
 
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 exampleShailesh singh
 
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 exampleShailesh singh
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 
WebAppSec Updates from W3C
WebAppSec Updates from W3CWebAppSec Updates from W3C
WebAppSec Updates from W3CNatasha Rooney
 

Similar a 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
RestRest
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
 
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
 

Más de 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 BodiesDomenic Denicola
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)Domenic Denicola
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great JusticeDomenic Denicola
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js PlatformDomenic Denicola
 
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...Domenic Denicola
 

Más de 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...
 

Último

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Último (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

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

Notas del editor

  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