SlideShare uma empresa Scribd logo
1 de 73
Baixar para ler offline
Teach a Dog to REST


Brian Mulloy
@landlessness

Apigee
@apigee
20%
Application developers are kingmakers.
Make your API easy to learn.
Good APIs are a design problem.
Idempotent methods
I won’t say things like that.
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
...
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                              /getSquirrelChasingPuppies

/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 URLs.
The first is for a collection.
/dogs
The second is for an element.
/dogs/bo
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/bo              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/bo   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/bo   error           show Bo                 delete Bo
                                       if not
                                       error



                   Wikipedia
Verbs are bad.
Nouns are good.
Plurals are better.
What about associations?
GET /owners/bob/dogs

POST /owners/bob/dogs
What about complex variations?
Cody Simms
Sweep variations under the ‘?’
/dogs?color=red&state=running&location=park
What about pagination?
Facebook
offset
limit


Twitter
page
rpp


LinkedIn
start
count
/dogs?limit=25&offset=50
What about searching?
Global
/search?q=fluffy+dog




Scoped
/owners/bob/dogs/search?q=fluffy
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 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/bo.json
What about partial updates?
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 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
dev.teachdogrest.com



Do web redirects
api ! dev

developers ! dev
developer ! dev
What about defaults?
Format
json



Pagination (depends on data size)
limit=10&offset=0
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/bo?method=put&location=park
delete

/dogs/bo?method=delete
Really? All of this? And iterate it?
Application




      API Virtualization Layer




API             API              API
Be RESTful
Only 2 URLs
No verbs
Use nouns as plurals
Sweep complexity behind the ‘?’
Borrow from leading APIs
Account for exceptional clients
Add virtualization layer
THANK YOU
Questions and ideas to:

Brian Mulloy
@landlessness
brian@apigee.com

Mais conteúdo relacionado

Mais procurados

Grails Simple Login
Grails Simple LoginGrails Simple Login
Grails Simple Login
moniguna
 

Mais procurados (20)

Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room Library
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Grails Simple Login
Grails Simple LoginGrails Simple Login
Grails Simple Login
 
Writing and using Hamcrest Matchers
Writing and using Hamcrest MatchersWriting and using Hamcrest Matchers
Writing and using Hamcrest Matchers
 
REST API testing with SpecFlow
REST API testing with SpecFlowREST API testing with SpecFlow
REST API testing with SpecFlow
 
React js
React jsReact js
React js
 
1. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES61. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES6
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Angular 2
Angular 2Angular 2
Angular 2
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Js: master prototypes
Js: master prototypesJs: master prototypes
Js: master prototypes
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 

Mais de Brian Mulloy

Applying Design Priciples to APIs - 2 of 4
Applying Design Priciples to APIs - 2 of 4 Applying Design Priciples to APIs - 2 of 4
Applying Design Priciples to APIs - 2 of 4
Brian Mulloy
 
KPIs for APIs - defrag 2010 - Brian Mulloy
KPIs for APIs - defrag 2010 - Brian MulloyKPIs for APIs - defrag 2010 - Brian Mulloy
KPIs for APIs - defrag 2010 - Brian Mulloy
Brian Mulloy
 

Mais de Brian Mulloy (6)

Swarms
SwarmsSwarms
Swarms
 
DetNodeCopterKickoff
DetNodeCopterKickoffDetNodeCopterKickoff
DetNodeCopterKickoff
 
Applying Design Priciples to APIs - 2 of 4
Applying Design Priciples to APIs - 2 of 4 Applying Design Priciples to APIs - 2 of 4
Applying Design Priciples to APIs - 2 of 4
 
Applying Design Priciples to APIs - 1 of 4
Applying Design Priciples to APIs - 1 of 4Applying Design Priciples to APIs - 1 of 4
Applying Design Priciples to APIs - 1 of 4
 
Two Ton API Client
Two Ton API ClientTwo Ton API Client
Two Ton API Client
 
KPIs for APIs - defrag 2010 - Brian Mulloy
KPIs for APIs - defrag 2010 - Brian MulloyKPIs for APIs - defrag 2010 - Brian Mulloy
KPIs for APIs - defrag 2010 - Brian Mulloy
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech 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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 

Teach a Dog to REST

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n