SlideShare a Scribd company logo
RESTful API Design
Second Edition



Brian Mulloy
@landlessness

                 11.03.11 @ 11:03:11 PST
Apigee           Dial-in or VoIP
@apigee          See Details in Chat Window
groups.google.com/group/api-craft
youtube.com/apigee
To be a RESTafarian or a Pragmatist?
RESTful API Design, Second Edition
App    App             App       World of          API   Internal
               App                          API
User   Store         Developer    APIs            Team   Systems
Application developers are raison d'être for APIs.
Be pragmatic.

For the benefit of application developers.
Pragmatic RESTful APIs are a design problem.
baddesigns.com
RESTful API Design, Second Edition
RESTful API Design, Second Edition
Paul Mijksenaar Design for Function Award 2011
RESTful API Design, Second Edition
Let’s look at puppies.
hackett   hackett




hackett   hackett
...
/getAllDogs
/locationVerify
/foodNeeded
/createRecurringDogWalk
/giveDirectOrder
/healthCheck
/getRecurringDogWalkSchedule
/getLocation
/getDog
/massDogParty
/getNewDogsSince
/getRedDogs
/getSittingDogs
/dogStateChangesSearch
/replaceSittingDogsWithRunningDogs
/saveDog
...
RESTful API Design, Second Edition
A puppy’s world is big.
JnL               law_keven




Smithsonian's National Zoo    hackett
...                                  ...

/getAllDogs                          /getAllLeashedDogs

/verifyLocation                      /verifyVeterinarianLocation

/feedNeeded                          /feedNeededFood

/createRecurringWakeUp               /createRecurringMedication

/giveDirectOrder                     /doDirectOwnerDiscipline

/checkHealth                         /doExpressCheckupWithVeterinarian

/getRecurringWakeUpSchedule          /getRecurringFeedingSchedule

/getLocation                         /getHungerLevel

/getDog                              /getSquirrelsChasingPuppies

/newDog                              /newDogForOwner

/getNewDogsSince                     /getNewDogsAtKennelSince

/getRedDogs                          /getRedDogsWithoutSiblings

/getSittingDogs                      /getSittingDogsAtPark

/setDogStateTo                       /setLeashedDogStateTo

/replaceSittingDogsWithRunningDogs   /replaceParkSittingDogsWithRunningDogs

/saveDog                             /saveMommaDogsPuppies

...                                  ...
We are on a slippery slope.
Keep the simple things simple.
Hopkinsii
We only need two base URLs per resource.
The first is for a collection.
/dogs
The second is for an element.
/dogs/1234
POST
GET
PUT
DELETE
CREATE
READ
UPDATE
DELETE
Resource      POST            GET        PUT        DELETE
               create          read      update      delete




                                       replace
             create a                              delete all
  /dogs                    list dogs   dogs with
             new dog                               dogs
                                       new dogs


                                       if exists
             treat as a
                                       update Bo
             collection
/dogs/1234              show Bo                    delete Bo
             create new
                                       if not
             dog in it
                                       create Bo



                   Wikipedia
Resource      POST            GET        PUT       DELETE
               create          read      update      delete




                                       replace
             create a                            delete all
  /dogs                    list dogs   dogs with
             new dog                             dogs
                                       new dogs


             treat as a                if exists
             collection                update Bo
/dogs/1234   create     show Bo                    delete Bo
             new dog                   if not
             in it                     create Bo



                   Wikipedia
Resource      POST              GET        PUT        DELETE
               create            read      update      delete




                                         bulk
             create a                                delete all
  /dogs                      list dogs   update
             new dog                                 dogs
                                         dogs


                                         if exists
                                         update Bo
/dogs/1234   error           show Bo                 delete Bo
                                         if not
                                         error



                     Wikipedia
Verbs are bad.
Nouns are good.
Plurals or singulars?
Foursquare
/checkins



GroupOn
/deals



Zappos
/Product
Plurals are better.

/dogs
Abstract or concrete naming?
Super High
/things


High
/animals


Medium
/dogs


Low
/beagles
Concrete is better than abstract.
/dogs
What about associations?
GET /owners/5678/dogs

POST /owners/5678/dogs
What about complex variations?
Cody Simms
Sweep variations under the ‘?’
/dogs?color=red&state=running&location=park
Hopkinsii
/dogs
What about errors?
meredithfarmer
Facebook            HTTP Status Code: 200

{"type":"OAuthException","message":"(#803) Some
of the aliases you requested do not exist:
foo.bar"}




Twilio              HTTP Status Code: 401

{"status":401,"message":"Authenticate","code":
20003,"more_info":"http://www.twilio.com/docs/
errors/20003"}




SimpleGeo           HTTP Status Code: 401

{"code":401,"message":"Authentication
Required"}
Code for code
200 - OK

401 - Unauthorized
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes




Message for people
{“message” : “Verbose, plain language
description of the problem with hints about
how to fix it.”
“more_info” : “http://dev.teachdogrest.com/
errors/12345”}
What about versioning?
Twilio
/2010-04-01/Accounts/



salesforce.com
/services/data/v20.0/sobjects/Account



Facebook
?v=1.0
/v1/dogs
Please give me exactly what I need.
LinkedIn
/people:(id,first-name,last-name,industry)




Facebook
/joe.smith/friends?fields=id,name,picture




Google (partial response)
?fields=title,media:group(media:thumbnail)
/dogs?fields=name,color,location
What about pagination?
Facebook
offset
limit


Twitter
page
rpp


LinkedIn
start
count
/dogs?limit=25&offset=50
What about formats?
Google Data
?alt=json



Foursquare
/venue.json



Digg*
Accept: application/json
?type=json
* The type argument, if present, overrides the Accept header.
/dogs.json


/dogs/1234.json
What about defaults?
Format
json



Pagination (depends on data size)
limit=10&offset=0
What about attribute names?
Twitter
"created_at": "Thu Nov 03 05:19:38 +0000 2011"




Bing
"DateTime": "2011-10-29T09:35:00Z"




Foursquare
"createdAt": 1320296464
JSON is for JavaScript Objects
var myObject = JSON.parse(response);



These looks funny in JavaScript

timing = myObject.created_at;

timing = myObject.DateTime;
JavaScript Convention
"createdAt": 1320296464


timing = myObject.createdAt;

Medial Capitalization aka CamelCase
What about non-resource-y stuff?
Calculate

Translate

Convert
Use verbs not nouns
/convert?from=EUR&to=CNY&amount=100
What about searching?
Global
/search?q=fluffy+fur



Scoped
/owners/5678/dogs/search?q=fluffy+fur



Formatted
/search.xml?q=fluffy+fur
What about counts?
/dogs/count
What about the rest of the URL?
Facebook    graph.facebook.com

             api.facebook.com

             developers.facebook.com



Foursquare   api.foursquare.com
             developers.foursquare.com



   Twitter   api.twitter.com

             search.twitter.com

             stream.twitter.com

             dev.twitter.com
API gateway
api.teachdogrest.com



Developer connection
developers.teachdogrest.com



Do web redirects
api ! developers (if from browser)

dev ! developers
developer ! developers
What about exceptional stuff?
Client intercepts HTTP error codes
Twitter

/public_timelines.json?
suppress_response_codes=true


HTTP Status Code: 200


{"error" : "Could not authenticate
you." }
Always returns OK
/dogs?suppress_response_codes=true


Code for code ignoring
200 - OK


Message for people & code
{“response_code” : “401”, “message” :
“Verbose, plain language description of the
problem with hints about how to fix it.”
“more_info” : “http://dev.teachdogrest.com/
errors/12345”, “code” : 12345}
Client supports limited HTTP methods
Method Parameter
create

/dogs?method=post
read

/dogs
update

/dogs/1234?method=put&location=park
delete

/dogs/1234?method=delete
What about authentication?
PayPal
Permissions Service API



Facebook
OAuth 2.0



Twitter
OAuth 1.0a
Use latest and greatest OAuth
OAuth 2.0
Don’t do something close, but different.
How do application developers use the API?
What about chatty applications?
First be complete & RESTful.


Then provide shortcuts.
Partial response syntax can help.

/owners/5678?fields=name,dogs(name)
What about when building an UI
requires a lot of domain knowledge?
RESTful API Design, Second Edition
Complement your API with code
libraries and SDK.
Really? All of this? And iterate it?
RESTful API Design, Second Edition
Application




      API Virtualization Layer




API             API              API
Be RESTful
Only 2 URLs
No verbs
Use nouns as plurals
Concrete over abstract
For JSON follow JavaScript conventions
Sweep complexity behind the ‘?’
Borrow from leading APIs
Account for exceptional clients
Add virtualization layer
Questions?
THANK YOU
Subscribe to API webinars at:
youtube.com/apigee
THANK YOU
Questions and ideas to:
groups.google.com/group/api-craft
THANK YOU
Contact me at:
@landlessness
brian@apigee.com

More Related Content

What's hot (20)

PPTX
API Management Part 1 - An Introduction to Azure API Management
BizTalk360
 
PPTX
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery
BlueHat Security Conference
 
PDF
Teach a Dog to REST
Brian Mulloy
 
PPTX
CI/CD with GitHub Actions
Swaminathan Vetri
 
PDF
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
Amazon Web Services Korea
 
PDF
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
Frans Rosén
 
PDF
Git-Dasar
Rahmat Sunjani
 
PPT
Git installation and configuration
Kishor Kumar
 
PDF
Creative Branching Models for Multiple Release Streams
Atlassian
 
PDF
Git flow
DaeMyung Kang
 
PDF
게임서비스를 위한 ElastiCache 활용 전략 :: 구승모 솔루션즈 아키텍트 :: Gaming on AWS 2016
Amazon Web Services Korea
 
PDF
Breaking The Cloud Kill Chain
Puma Security, LLC
 
PPTX
Github basics
Radoslav Georgiev
 
PPTX
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Soroush Dalili
 
PDF
Zero-Copy Event-Driven Servers with Netty
Daniel Bimschas
 
PDF
The 12 Factor App
rudiyardley
 
PDF
Git - An Introduction
Behzad Altaf
 
PPTX
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017
AWSKRUG - AWS한국사용자모임
 
PPTX
Git
Shinu Suresh
 
PDF
Microservices-DDD-Telosys-Devoxx-FR-2022
Laurent Guérin
 
API Management Part 1 - An Introduction to Azure API Management
BizTalk360
 
BlueHat v17 || Detecting Compromise on Windows Endpoints with Osquery
BlueHat Security Conference
 
Teach a Dog to REST
Brian Mulloy
 
CI/CD with GitHub Actions
Swaminathan Vetri
 
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
Amazon Web Services Korea
 
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
Frans Rosén
 
Git-Dasar
Rahmat Sunjani
 
Git installation and configuration
Kishor Kumar
 
Creative Branching Models for Multiple Release Streams
Atlassian
 
Git flow
DaeMyung Kang
 
게임서비스를 위한 ElastiCache 활용 전략 :: 구승모 솔루션즈 아키텍트 :: Gaming on AWS 2016
Amazon Web Services Korea
 
Breaking The Cloud Kill Chain
Puma Security, LLC
 
Github basics
Radoslav Georgiev
 
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Soroush Dalili
 
Zero-Copy Event-Driven Servers with Netty
Daniel Bimschas
 
The 12 Factor App
rudiyardley
 
Git - An Introduction
Behzad Altaf
 
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017
AWSKRUG - AWS한국사용자모임
 
Microservices-DDD-Telosys-Devoxx-FR-2022
Laurent Guérin
 

Viewers also liked (6)

PPTX
대용량 분산 아키텍쳐 설계 #5. rest
Terry Cho
 
PPTX
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
Terry Cho
 
PPTX
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
Terry Cho
 
PPTX
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
Terry Cho
 
PPTX
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
Terry Cho
 
PPTX
Global platform
Terry Cho
 
대용량 분산 아키텍쳐 설계 #5. rest
Terry Cho
 
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
Terry Cho
 
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
Terry Cho
 
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
Terry Cho
 
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
Terry Cho
 
Global platform
Terry Cho
 
Ad

Similar to RESTful API Design, Second Edition (10)

KEY
Pragmatic RESTful API Design: Apigee Webinar
Apigee | Google Cloud
 
PDF
Rails 3 Beginner to Builder 2011 Week 5
Richard Schneeman
 
KEY
Rails3 Summer of Code 2010- Week 5
Richard Schneeman
 
PPTX
API Simplicity + Consistency == Speed: Designing APIs That Are Easy and Fun t...
FamilySearch
 
PPTX
API Simplicity == Speed; Designing APIs That are Easy and Fun to Use
Harold Madsen
 
PPTX
Final pet stop
amru716
 
PPTX
API Design - 3rd Edition
Apigee | Google Cloud
 
PPTX
Tech pet stop_final
amru716
 
PDF
Webcast: Pragmatic REST: The Next Generation
Apigee | Google Cloud
 
PDF
Writing great documentation - CodeConf 2011
Jacob Kaplan-Moss
 
Pragmatic RESTful API Design: Apigee Webinar
Apigee | Google Cloud
 
Rails 3 Beginner to Builder 2011 Week 5
Richard Schneeman
 
Rails3 Summer of Code 2010- Week 5
Richard Schneeman
 
API Simplicity + Consistency == Speed: Designing APIs That Are Easy and Fun t...
FamilySearch
 
API Simplicity == Speed; Designing APIs That are Easy and Fun to Use
Harold Madsen
 
Final pet stop
amru716
 
API Design - 3rd Edition
Apigee | Google Cloud
 
Tech pet stop_final
amru716
 
Webcast: Pragmatic REST: The Next Generation
Apigee | Google Cloud
 
Writing great documentation - CodeConf 2011
Jacob Kaplan-Moss
 
Ad

More from Apigee | Google Cloud (20)

PDF
How Secure Are Your APIs?
Apigee | Google Cloud
 
PDF
Magazine Luiza at a glance (1)
Apigee | Google Cloud
 
PPTX
Monetization: Unlock More Value from Your APIs
Apigee | Google Cloud
 
PDF
Apigee Demo: API Platform Overview
Apigee | Google Cloud
 
PDF
Ticketmaster at a glance
Apigee | Google Cloud
 
PDF
AccuWeather: Recasting API Experiences in a Developer-First World
Apigee | Google Cloud
 
PDF
Which Application Modernization Pattern Is Right For You?
Apigee | Google Cloud
 
PPTX
Apigee Product Roadmap Part 2
Apigee | Google Cloud
 
PPTX
The Four Transformative Forces of the API Management Market
Apigee | Google Cloud
 
PDF
Walgreens at a glance
Apigee | Google Cloud
 
PDF
Apigee Edge: Intro to Microgateway
Apigee | Google Cloud
 
PDF
Managing the Complexity of Microservices Deployments
Apigee | Google Cloud
 
PDF
Pitney Bowes at a glance
Apigee | Google Cloud
 
PPTX
Microservices Done Right: Key Ingredients for Microservices Success
Apigee | Google Cloud
 
PDF
Adapt or Die: Opening Keynote with Chet Kapoor
Apigee | Google Cloud
 
PDF
Adapt or Die: Keynote with Greg Brail
Apigee | Google Cloud
 
PDF
Adapt or Die: Keynote with Anant Jhingran
Apigee | Google Cloud
 
PDF
London Adapt or Die: Opening Keynot
Apigee | Google Cloud
 
PDF
London Adapt or Die: Lunch keynote
Apigee | Google Cloud
 
PDF
London Adapt or Die: Closing Keynote — Adapt Now!
Apigee | Google Cloud
 
How Secure Are Your APIs?
Apigee | Google Cloud
 
Magazine Luiza at a glance (1)
Apigee | Google Cloud
 
Monetization: Unlock More Value from Your APIs
Apigee | Google Cloud
 
Apigee Demo: API Platform Overview
Apigee | Google Cloud
 
Ticketmaster at a glance
Apigee | Google Cloud
 
AccuWeather: Recasting API Experiences in a Developer-First World
Apigee | Google Cloud
 
Which Application Modernization Pattern Is Right For You?
Apigee | Google Cloud
 
Apigee Product Roadmap Part 2
Apigee | Google Cloud
 
The Four Transformative Forces of the API Management Market
Apigee | Google Cloud
 
Walgreens at a glance
Apigee | Google Cloud
 
Apigee Edge: Intro to Microgateway
Apigee | Google Cloud
 
Managing the Complexity of Microservices Deployments
Apigee | Google Cloud
 
Pitney Bowes at a glance
Apigee | Google Cloud
 
Microservices Done Right: Key Ingredients for Microservices Success
Apigee | Google Cloud
 
Adapt or Die: Opening Keynote with Chet Kapoor
Apigee | Google Cloud
 
Adapt or Die: Keynote with Greg Brail
Apigee | Google Cloud
 
Adapt or Die: Keynote with Anant Jhingran
Apigee | Google Cloud
 
London Adapt or Die: Opening Keynot
Apigee | Google Cloud
 
London Adapt or Die: Lunch keynote
Apigee | Google Cloud
 
London Adapt or Die: Closing Keynote — Adapt Now!
Apigee | Google Cloud
 

Recently uploaded (20)

PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
July Patch Tuesday
Ivanti
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Biography of Daniel Podor.pdf
Daniel Podor
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 

RESTful API Design, Second Edition