SlideShare a Scribd company logo
1 of 110
API Anti Patterns
   or, how to not f**k up your API
API Anti Patterns
   or, how to not f**k up your API
or, tips on how to annoy your API consumers
or, think you know REST? Awesome!
or, some of the crazy s**t people do with REST
Hello
Mike
Pearce
http://social-network.com




/MikePearce
http://social-network.com




/MikeyPearce
http://social-network.com




/mikepearce.net
http://social-network.com




/MikePearce
An
Apology
RE
       HE h
    ISP ort
S ON ebw
 @ Kn




      Flags shoul
                 d be banne
                           d a festival
                                       s!
Bu rritos:
              l. Food . Ever.
Best. Festiva
Mike, Lee and Rog
SORRY
(     HTTP REQUEST:

                             )
    That you get on with it...
a mIh ere?
Why




REST
a mIh ere?
Why




REST
a mIh ere?
Why




REST               Ha
                     h!
a mIh ere?
Why




  ST
REST               Hu
                     h?!
Do’s   ✔
Do’s     ✔
Dont’s   ✘
Do’s      ✔
Dont’s    ✘
Whatevs.. ☠
Some
 But fi rst...



background
Who?




Roy Fielding (the grandfather)
There!
Architectural
Styles and the
     Design of
     Network-
 Can’t s
   ead tbased
         leep?
          his...

     Software
  R



Architectures
A    A
  nd now ...


 quick
primer
REST != HTTP
REST != HTTP
REST != The Web
REST
REST
IS NOT
REST
IS NOT
     HA
REST
IS NOT
Se
     HA
   riou sly!
Standards? We
don’t need no
   steenkin’
  standards!
MY CONSTRAINTS,
LET ME SHOW YOU THEM
e ve rbs...
Som
e nou ns...
Som
GET
PINT
PINT
 Plea se!
main event
Ont o the




 ANTI
    patterns
Overuse of ...
GET
Overuse of
GET and POST
   or, GET/POST tunnelling.
GET:



                BA
http://api.flickr.com/services/
rest/?method=
flickr.photos.people.add
&api_key=nnn&photo_id=yyy&u
ser_id=xxx
PUT: /user/MikePearce
api_key=moo&
age=33&
size=medium&
power=flight

         GOOD
PUT or POST?

PUT: /users/MikePearce
PUT: /links/google
PUT: /articles/100805/putorpost

           ASIDE
PUT or POST?

POST: /documents/save
name=styleguide.css&
category=design

          ASIDE
PUT or POST?
PUT when the resource will live
at the target URI
POST when you want the
server to handle the location of
the resource.
           ASIDE
POST: /dostuff/
user=MikePearce&


             BA
action=delete&
api_key=moo&
token=quack&
mode=3
DELETE:
  /user/MikePearce


          Wait! W
                  hat? Wh
                          y!?


       GOOD
Tunneling
    Errors
  through
Are you OK?




               I’m fine!



Great! A 200
   OK!
Are you
                    OK?


                   I’m fine!



Great! A 200
   OK!           ARGGHH! He
               doesn’t understand
                       me!
This is better...
GET: /droid/r2d2
      GET: /droid/c3po




404: Not the droids you’re
               looking for
HTTP/1.1 200 OK
Content-Type: text/plain
<?xml version="1.0" encoding="UTF-8" ?>
<response code="error">
  <error>Error!</error>
  <text>You have errored.</text>
                                   ed t o do
</response>              I su ppos
                   What am     this?
                          with
Which leads me nicely to...


RESPONSE
 CODES
IE has
            failed




Informational
FTW!1
   Success
Redirection
illust rating
(yo u try
       ent er  ror!)
    cli



Client Error
n’t fi nd an
   s 1am . I ca       error.
It’           erver
 i mage for s




                Server Error
PUT: /user/MikePearce

HTTP/1.1 200 OK


    Meh..
PUT: /user/MikePearce

HTTP/1.1 201 CREATED


    Huzzah!
GET: /whatareyou

HTTP/1.1 418
GET: /whatareyou

HTTP/1.1 418
I’m a teapot

           is real1!!
This   one
Caching
E-Tags
HTTP/1.1 304 NOT
MODIFIED
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Last-Modified: Wed, 08 Jan 2003 23:11:55
Etag: "3f80f-1b6-3e1cb03b"
Connection: close
Content-Type: text/html; charset=UTF-8
Mmm ... Delicious!
NO
HYPERMEDIA
HYPERMEDIA
 What is it?
HYPERMEDIA
 What is it?
HYPERMEDIA
  AS THE
 ENGINE OF
APPLICATION
   STATE
oar...
HATEOAS
(Remember hating oars)
Grey Areas
V3r510n1ng
   Versioning
GET: /user/MikePearce
              in. Prolific
      Him aga
           bas tard.
GET: /user/MikePearce
    GET: /user/66
1. Versioning with the URI



GET: /v1/user/MikePearce
    GET: /v2/user/66
2. Not versioning the primary URI



      GET: /user/66
GET: /v1/user/MikePearce
3. No versioning



GET: /user/66
Document
Extensions
Either
Either
GET: /reports/tpsreport/summary.json
GET: /reports/tpsreport/summary.xml
Either
GET: /reports/tpsreport/summary.json
GET: /reports/tpsreport/summary.xml


                or
Either
GET: /reports/tpsreport/summary.json
GET: /reports/tpsreport/summary.xml


                or

      Accept: text/xml
      Accept: application/json
SUM
 Phew!




MARY
Overuse of
GET and POST
   or, GET/POST tunnelling.
Tunneling
    Errors
  through
Which leads me nicely to...


RESPONSE
 CODES
E-Tags
NO
HATEOAS
(Remember hating oars)
V3r510n1ng
   Versioning
Either
GET: /reports/tpsreport/summary.json
GET: /reports/tpsreport/summary.xml


                or

      Accept: text/xml
      Accept: application/json
Any qu estions?
                  swer!)
   (that I can an
Photo Credits


Wordle.net
flickr.com/photos/wouterkiel/3717057757/ - Wouter Kiel
flickr.com/photos/joe_13/19946186/ - joe_13
flickr.com/photos/23846880@N00/391925649/ - Rutger de Moddertukker
flickr.com/photos/mararie/264942105/ - mararie
flickr.com/photos/ndanger/7841795/ - ndanger
flickr.com/photos/yourdon/2573762303/ - Ed Yourdon
flickr.com/photos/thunderchild5/225675773/ - Thunderchild7
flickr.com/photos/duchamp/126115989/ - Duchamp
flickr.com/photos/thefangmonster/490423135/ - The fang monster
flickr.com/photos/nostri-imago/2894328425/ - cliff1066
flickr.com/photos/epsos/4582789354/ - epSos.de
flickr.com/photos/projector/2092517108/ - allie pasquier
flickr.com/photos/nickstone333/3135320160/ - nickstone333
flickr.com/photos/rdrcollection/116454033/ - Rodney Ramsey
flickr.com/photos/christophercarfi/2730304130/ - Christophercarfi
flickr.com/photos/turatti/4526352835/ - jaci xIII
Thanks!




          Mike
             Pearce
 mike@mikepearce.net
     mikepearce.net
twtitter.com/mikepearce

More Related Content

What's hot

Assistive tech pecha kucha
Assistive tech pecha kuchaAssistive tech pecha kucha
Assistive tech pecha kuchaceholland
 
Assistive tech pecha kucha
Assistive tech pecha kuchaAssistive tech pecha kucha
Assistive tech pecha kuchaMatt Stone
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...Baruch Sadogursky
 
Multimedia resources for librarians
Multimedia resources for librariansMultimedia resources for librarians
Multimedia resources for librariansPhil Bradley
 
PPP Finale - Thomas Hausler
PPP Finale - Thomas HauslerPPP Finale - Thomas Hausler
PPP Finale - Thomas HauslerThausler
 
Practical Podcasting
Practical PodcastingPractical Podcasting
Practical Podcastingdwfree
 
RENNIE COWAN - RED CARPET INTERVIEWS
RENNIE COWAN - RED CARPET INTERVIEWSRENNIE COWAN - RED CARPET INTERVIEWS
RENNIE COWAN - RED CARPET INTERVIEWSRennie Cowan
 
Cultivating a Community Around Live Video
Cultivating a Community Around Live VideoCultivating a Community Around Live Video
Cultivating a Community Around Live VideoAffiliate Summit
 
Structuring apps in Scala
Structuring apps in ScalaStructuring apps in Scala
Structuring apps in ScalaPhil Calçado
 
Fssf community overview
Fssf community overviewFssf community overview
Fssf community overviewSergey Tihon
 
RENNIE COWAN - MUSIC VIDEO REEL
RENNIE COWAN - MUSIC VIDEO REELRENNIE COWAN - MUSIC VIDEO REEL
RENNIE COWAN - MUSIC VIDEO REELRennie Cowan
 
Repositorios de audio, imagenes, videos y documentos
Repositorios de audio, imagenes, videos y documentosRepositorios de audio, imagenes, videos y documentos
Repositorios de audio, imagenes, videos y documentosSheila Espinoza
 

What's hot (17)

MozStory 2014
MozStory 2014MozStory 2014
MozStory 2014
 
Assistive tech pecha kucha
Assistive tech pecha kuchaAssistive tech pecha kucha
Assistive tech pecha kucha
 
Assistive tech pecha kucha
Assistive tech pecha kuchaAssistive tech pecha kucha
Assistive tech pecha kucha
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Detroit...
 
Multimedia resources for librarians
Multimedia resources for librariansMultimedia resources for librarians
Multimedia resources for librarians
 
3 S's to a Successful Launch
3 S's to a Successful Launch3 S's to a Successful Launch
3 S's to a Successful Launch
 
PPP Finale - Thomas Hausler
PPP Finale - Thomas HauslerPPP Finale - Thomas Hausler
PPP Finale - Thomas Hausler
 
Practical Podcasting
Practical PodcastingPractical Podcasting
Practical Podcasting
 
RENNIE COWAN - RED CARPET INTERVIEWS
RENNIE COWAN - RED CARPET INTERVIEWSRENNIE COWAN - RED CARPET INTERVIEWS
RENNIE COWAN - RED CARPET INTERVIEWS
 
Cultivating a Community Around Live Video
Cultivating a Community Around Live VideoCultivating a Community Around Live Video
Cultivating a Community Around Live Video
 
Structuring apps in Scala
Structuring apps in ScalaStructuring apps in Scala
Structuring apps in Scala
 
Volvo prosis disc 4 edit
Volvo prosis disc 4 editVolvo prosis disc 4 edit
Volvo prosis disc 4 edit
 
Fssf community overview
Fssf community overviewFssf community overview
Fssf community overview
 
RENNIE COWAN - MUSIC VIDEO REEL
RENNIE COWAN - MUSIC VIDEO REELRENNIE COWAN - MUSIC VIDEO REEL
RENNIE COWAN - MUSIC VIDEO REEL
 
Repositorios de audio, imagenes, videos y documentos
Repositorios de audio, imagenes, videos y documentosRepositorios de audio, imagenes, videos y documentos
Repositorios de audio, imagenes, videos y documentos
 
Biologia y laboratorio_1_quimica_2020
Biologia y laboratorio_1_quimica_2020Biologia y laboratorio_1_quimica_2020
Biologia y laboratorio_1_quimica_2020
 
Experiência 1
Experiência 1Experiência 1
Experiência 1
 

Viewers also liked

APIs: the Glue of Cloud Computing
APIs: the Glue of Cloud ComputingAPIs: the Glue of Cloud Computing
APIs: the Glue of Cloud Computing3scale
 
How To Design A Good A P I And Why It Matters G O O G L E
How To Design A Good  A P I And Why It Matters    G O O G L EHow To Design A Good  A P I And Why It Matters    G O O G L E
How To Design A Good A P I And Why It Matters G O O G L Eguestbe92f4
 
5 Anti-Patterns in Api Design - buildstuff
5 Anti-Patterns in Api Design - buildstuff5 Anti-Patterns in Api Design - buildstuff
5 Anti-Patterns in Api Design - buildstuffAli Kheyrollahi
 
Golden Rules of API Design
Golden Rules of API DesignGolden Rules of API Design
Golden Rules of API DesignDavid Koelle
 
Exploitez toute la valeur de vos données client et produit grâce à talend 6
Exploitez toute la valeur de vos données client et produit grâce à talend 6Exploitez toute la valeur de vos données client et produit grâce à talend 6
Exploitez toute la valeur de vos données client et produit grâce à talend 6Jean-Michel Franco
 
Atelier Talend - Forum MDM Micropole 2014 - Du MDM client à la customer dat...
Atelier Talend -  Forum MDM Micropole 2014 -  Du MDM client à la customer dat...Atelier Talend -  Forum MDM Micropole 2014 -  Du MDM client à la customer dat...
Atelier Talend - Forum MDM Micropole 2014 - Du MDM client à la customer dat...Micropole Group
 
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009Cesare Pautasso
 
Intégration des données avec Talend ETL
Intégration des données avec Talend ETLIntégration des données avec Talend ETL
Intégration des données avec Talend ETLLilia Sfaxi
 
Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...
Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...
Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...Data Con LA
 
Adding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of TricksAdding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of Trickssiculars
 
Antipatrones de Software
Antipatrones de SoftwareAntipatrones de Software
Antipatrones de SoftwareMartin Salias
 
ThoughtWorks Continuous Delivery
ThoughtWorks Continuous DeliveryThoughtWorks Continuous Delivery
ThoughtWorks Continuous DeliveryKyle Hodgson
 
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...Concordia University
 
Patterns and Antipatterns for Adopting IBM DevOps Tools
Patterns and Antipatterns for Adopting IBM DevOps ToolsPatterns and Antipatterns for Adopting IBM DevOps Tools
Patterns and Antipatterns for Adopting IBM DevOps ToolsStrongback Consulting
 
Antipatrones de desarrollo de software
Antipatrones de desarrollo de softwareAntipatrones de desarrollo de software
Antipatrones de desarrollo de softwarePablo Bouzada
 
The hypermedia api
The hypermedia apiThe hypermedia api
The hypermedia apiInviqa
 
Talend Data Mapper : Simplifiez-vous l'intégration de SAP !
Talend Data Mapper : Simplifiez-vous l'intégration de SAP !Talend Data Mapper : Simplifiez-vous l'intégration de SAP !
Talend Data Mapper : Simplifiez-vous l'intégration de SAP !Synaltic Group
 
Découvrir le web sémantique en 15 minutes (Decideo 2014)
Découvrir le web sémantique en 15 minutes (Decideo 2014)Découvrir le web sémantique en 15 minutes (Decideo 2014)
Découvrir le web sémantique en 15 minutes (Decideo 2014)François Belleau
 

Viewers also liked (20)

APIs: the Glue of Cloud Computing
APIs: the Glue of Cloud ComputingAPIs: the Glue of Cloud Computing
APIs: the Glue of Cloud Computing
 
How To Design A Good A P I And Why It Matters G O O G L E
How To Design A Good  A P I And Why It Matters    G O O G L EHow To Design A Good  A P I And Why It Matters    G O O G L E
How To Design A Good A P I And Why It Matters G O O G L E
 
5 Anti-Patterns in Api Design - buildstuff
5 Anti-Patterns in Api Design - buildstuff5 Anti-Patterns in Api Design - buildstuff
5 Anti-Patterns in Api Design - buildstuff
 
Golden Rules of API Design
Golden Rules of API DesignGolden Rules of API Design
Golden Rules of API Design
 
Exploitez toute la valeur de vos données client et produit grâce à talend 6
Exploitez toute la valeur de vos données client et produit grâce à talend 6Exploitez toute la valeur de vos données client et produit grâce à talend 6
Exploitez toute la valeur de vos données client et produit grâce à talend 6
 
Atelier Talend - Forum MDM Micropole 2014 - Du MDM client à la customer dat...
Atelier Talend -  Forum MDM Micropole 2014 -  Du MDM client à la customer dat...Atelier Talend -  Forum MDM Micropole 2014 -  Du MDM client à la customer dat...
Atelier Talend - Forum MDM Micropole 2014 - Du MDM client à la customer dat...
 
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
Some REST Design Patterns (and Anti-Patterns) - SOA Symposium 2009
 
Intégration des données avec Talend ETL
Intégration des données avec Talend ETLIntégration des données avec Talend ETL
Intégration des données avec Talend ETL
 
RESTful API Design, Second Edition
RESTful API Design, Second EditionRESTful API Design, Second Edition
RESTful API Design, Second Edition
 
Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...
Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...
Big Data Day LA 2015 - How to model anything in Redis by Josiah Carlson of Ze...
 
Adding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of TricksAdding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of Tricks
 
Antipatrones de Software
Antipatrones de SoftwareAntipatrones de Software
Antipatrones de Software
 
Anti patrones
Anti patronesAnti patrones
Anti patrones
 
ThoughtWorks Continuous Delivery
ThoughtWorks Continuous DeliveryThoughtWorks Continuous Delivery
ThoughtWorks Continuous Delivery
 
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...
ICSE2014 - Detecting Performance Anti-patterns for Applications Developed usi...
 
Patterns and Antipatterns for Adopting IBM DevOps Tools
Patterns and Antipatterns for Adopting IBM DevOps ToolsPatterns and Antipatterns for Adopting IBM DevOps Tools
Patterns and Antipatterns for Adopting IBM DevOps Tools
 
Antipatrones de desarrollo de software
Antipatrones de desarrollo de softwareAntipatrones de desarrollo de software
Antipatrones de desarrollo de software
 
The hypermedia api
The hypermedia apiThe hypermedia api
The hypermedia api
 
Talend Data Mapper : Simplifiez-vous l'intégration de SAP !
Talend Data Mapper : Simplifiez-vous l'intégration de SAP !Talend Data Mapper : Simplifiez-vous l'intégration de SAP !
Talend Data Mapper : Simplifiez-vous l'intégration de SAP !
 
Découvrir le web sémantique en 15 minutes (Decideo 2014)
Découvrir le web sémantique en 15 minutes (Decideo 2014)Découvrir le web sémantique en 15 minutes (Decideo 2014)
Découvrir le web sémantique en 15 minutes (Decideo 2014)
 

Similar to Api anti patterns

Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...
Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...
Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...javier ramirez
 
Startup and Rapid web development
Startup and Rapid web developmentStartup and Rapid web development
Startup and Rapid web developmentLalit Shandilya
 
Engineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better PerformanceEngineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better PerformanceSC5.io
 
Mistakes I Made Building Netflix for the iPhone
Mistakes I Made Building Netflix for the iPhoneMistakes I Made Building Netflix for the iPhone
Mistakes I Made Building Netflix for the iPhonekentbrew
 
Podcast & Screencasting On Rails
Podcast & Screencasting On RailsPodcast & Screencasting On Rails
Podcast & Screencasting On Railsguest75489e
 
Pragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee WebinarPragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee WebinarApigee | Google Cloud
 
Webspam (English Version)
Webspam (English Version)Webspam (English Version)
Webspam (English Version)Dirk Haun
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTfulgoldoraf
 
15 Ways To A Blistering-Fast Web Site
15 Ways To A Blistering-Fast Web Site15 Ways To A Blistering-Fast Web Site
15 Ways To A Blistering-Fast Web SiteIan Lurie
 
Web performance optimization
Web performance optimizationWeb performance optimization
Web performance optimizationKaliop-slide
 
Stefan Judis "Did we(b development) lose the right direction?"
Stefan Judis "Did we(b development) lose the right direction?"Stefan Judis "Did we(b development) lose the right direction?"
Stefan Judis "Did we(b development) lose the right direction?"Fwdays
 
VDay 2015 - Golang as the Dream of a Devops Engineer
VDay 2015 - Golang as the Dream of a Devops EngineerVDay 2015 - Golang as the Dream of a Devops Engineer
VDay 2015 - Golang as the Dream of a Devops EngineerMáté Gulyás
 
WebRTC Reborn - Full Stack Toronto
WebRTC Reborn -  Full Stack TorontoWebRTC Reborn -  Full Stack Toronto
WebRTC Reborn - Full Stack TorontoDan Jenkins
 
Voicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoxeo Corp
 
RWD in the Wild
RWD in the WildRWD in the Wild
RWD in the WildRich Quick
 
Building Twitter in Drupal
Building Twitter in DrupalBuilding Twitter in Drupal
Building Twitter in DrupalJeff Eaton
 
Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123Hina Chen
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrJohn Allspaw
 
RESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an IntroductionRESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an IntroductionMiredot
 

Similar to Api anti patterns (20)

Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...
Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...
Rails is not enough, by Javier Ramirez, at Conferencia Rails 2010 in Madrid, ...
 
Startup and Rapid web development
Startup and Rapid web developmentStartup and Rapid web development
Startup and Rapid web development
 
Engineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better PerformanceEngineering HTML5 Applications for Better Performance
Engineering HTML5 Applications for Better Performance
 
Mistakes I Made Building Netflix for the iPhone
Mistakes I Made Building Netflix for the iPhoneMistakes I Made Building Netflix for the iPhone
Mistakes I Made Building Netflix for the iPhone
 
Podcast & Screencasting On Rails
Podcast & Screencasting On RailsPodcast & Screencasting On Rails
Podcast & Screencasting On Rails
 
Pragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee WebinarPragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee Webinar
 
Webspam (English Version)
Webspam (English Version)Webspam (English Version)
Webspam (English Version)
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTful
 
15 Ways To A Blistering-Fast Web Site
15 Ways To A Blistering-Fast Web Site15 Ways To A Blistering-Fast Web Site
15 Ways To A Blistering-Fast Web Site
 
Web performance optimization
Web performance optimizationWeb performance optimization
Web performance optimization
 
Stefan Judis "Did we(b development) lose the right direction?"
Stefan Judis "Did we(b development) lose the right direction?"Stefan Judis "Did we(b development) lose the right direction?"
Stefan Judis "Did we(b development) lose the right direction?"
 
Intro to Silex
Intro to SilexIntro to Silex
Intro to Silex
 
VDay 2015 - Golang as the Dream of a Devops Engineer
VDay 2015 - Golang as the Dream of a Devops EngineerVDay 2015 - Golang as the Dream of a Devops Engineer
VDay 2015 - Golang as the Dream of a Devops Engineer
 
WebRTC Reborn - Full Stack Toronto
WebRTC Reborn -  Full Stack TorontoWebRTC Reborn -  Full Stack Toronto
WebRTC Reborn - Full Stack Toronto
 
Voicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.com
 
RWD in the Wild
RWD in the WildRWD in the Wild
RWD in the Wild
 
Building Twitter in Drupal
Building Twitter in DrupalBuilding Twitter in Drupal
Building Twitter in Drupal
 
Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123Webconf 2013 - Media Query 123
Webconf 2013 - Media Query 123
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and Flickr
 
RESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an IntroductionRESTFul API Design and Documentation - an Introduction
RESTFul API Design and Documentation - an Introduction
 

More from Mike Pearce

Agile Estimation
Agile EstimationAgile Estimation
Agile EstimationMike Pearce
 
The Shuhari of Agile
The Shuhari of AgileThe Shuhari of Agile
The Shuhari of AgileMike Pearce
 
UX For Developers
UX For DevelopersUX For Developers
UX For DevelopersMike Pearce
 
Thimbl: decentralised, open source, micro-blogging
Thimbl: decentralised, open source, micro-bloggingThimbl: decentralised, open source, micro-blogging
Thimbl: decentralised, open source, micro-bloggingMike Pearce
 
Writing Effective User Stories
Writing Effective User StoriesWriting Effective User Stories
Writing Effective User StoriesMike Pearce
 
Introduction to Unit Testing
Introduction to Unit TestingIntroduction to Unit Testing
Introduction to Unit TestingMike Pearce
 

More from Mike Pearce (7)

Agile Estimation
Agile EstimationAgile Estimation
Agile Estimation
 
The Shuhari of Agile
The Shuhari of AgileThe Shuhari of Agile
The Shuhari of Agile
 
Being Agile
Being AgileBeing Agile
Being Agile
 
UX For Developers
UX For DevelopersUX For Developers
UX For Developers
 
Thimbl: decentralised, open source, micro-blogging
Thimbl: decentralised, open source, micro-bloggingThimbl: decentralised, open source, micro-blogging
Thimbl: decentralised, open source, micro-blogging
 
Writing Effective User Stories
Writing Effective User StoriesWriting Effective User Stories
Writing Effective User Stories
 
Introduction to Unit Testing
Introduction to Unit TestingIntroduction to Unit Testing
Introduction to Unit Testing
 

Api anti patterns

Editor's Notes

  1. Welcome to PHPLondon August 2010 meetup. I&amp;#x2019;m here to talk about API Antipatterns and, more specifically, the use of REST.
  2. or, some great ways to piss off your customers and users.
  3. or, I&amp;#x2019;m going to teach you to suck eggs.
  4. or, we&amp;#x2019;ll just laugh at other peoples&amp;#x2019; expense.
  5. So, hello, thanks for coming, you&amp;#x2019;re all wonderful, really.
  6. My name is Mike Pearce, this is my avatar, you&amp;#x2019;ll see it liberally splashed about on various social networks.
  7. You can usually find me as &amp;#x2018;MikePearce&amp;#x2019; on most networks.
  8. or &amp;#x2018;MikeyPearce&amp;#x2019;
  9. or even mikepearce.net
  10. but, mostly MikePearce. I work for Affiliate Window, although I&amp;#x2019;ve only been there two days, so don&amp;#x2019;t ask me anything about them. Anyway, my contact details will be at the end if you&amp;#x2019;re still awake, or even still here...
  11. Firstly an apology. this presentation is ill written, probably badly researched and definately un-rehearsed. I only had a couple of weeks notice and most of that time was already taken up with things like working, eating sleeping and high-maintenance children.
  12. I also went to a festival, Sonisphere at Knebworth
  13. I ate too much
  14. Drank too much
  15. and everything I had ever learned about my job fell out of my head for four days. Monday arrived, then Tuesday and I still hadn&amp;#x2019;t done it.
  16. So, along with starting a new job, I&amp;#x2019;ve spent the last 48hours glued to Keynote.
  17. Anyway, I shall get on with it now.
  18. You probably think I am here to talk about REST, right?
  19. Well, I&amp;#x2019;m not.
  20. Actually, I am ... sort of. I&amp;#x2019;m here to talk about how NOT to do rest, which is much easier!
  21. The do&amp;#x2019;s, the dont&amp;#x2019;s and the whatevs of a REST API.
  22. Roy Fielding is a 45 year old Californian who ...
  23. Is one of the principle authors of the HTTP 1.1 RFC
  24. He also wrote a dissertation in 2000 called &amp;#x2018;Architectural Styles andthe Design of Network-based Software Architectures&amp;#x2019; for a doctorate of philosophy. Hands up who has read this!
  25. ... and chapter 5 had all the meaty stuff about REST.
  26. Rest isn&amp;#x2019;t HTTP ...
  27. and REST isn&amp;#x2019;t &amp;#x2018;The Web&amp;#x2019;. I&amp;#x2019;ve heard REST summarised as Roy Fielding&amp;#x2019;s way of describing the existing architecture of the web. While this is true, that&amp;#x2019;s not all it is. REST principles can be applied with many other technologies.
  28. REST isn&amp;#x2019;t particularly hard to get right.
  29. REST isn&amp;#x2019;t particularly hard to get right.
  30. REST isn&amp;#x2019;t particularly hard to get right.
  31. REST isn&amp;#x2019;t particularly hard to get right.
  32. There aren&amp;#x2019;t really any standards.
  33. Just a few constraints and a couple of guidelines. http://www.flickr.com/photos/joe_13/19946186/ joe_13
  34. REST is really a set of verbs
  35. which are applied to nouns. Here is a short example...
  36. JON, can you
  37. me a pint
  38. So, let&amp;#x2019;s get into the anti patterns.
  39. So, the first antipattern and these aren&amp;#x2019;t in any particular order is..
  40. http://www.flickr.com/photos/23846880@N00/391925649/ Rutger de Moddertukker
  41. Probably one of the most obvious, yet most abused pattern is to use GET or POST for everything. As I mentioned earlier, REST is about applying verbs to nouns. The nouns HTTP has are few, granted, but still distinct enough to each have their own jobs. CAN YOU NAME ALL THE HTTP NOUNS?
  42. TRACE - Echoes back the received request, so that a client can see what (if any) changes or additions have been made by intermediate servers. OPTIONS - Returns the HTTP methods that the server supports for specified URL. CONNECT - Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy PATCH - Is used to apply partial modifications to a resource.[8]
  43. An example of GET tunnelling. While this is clear enough what&amp;#x2019;s it&amp;#x2019;s doing, it&amp;#x2019;s not adhering to a rest restraint, so, not really RESTful.
  44. Good example of storing a document
  45. PUT or POST is a question you&amp;#x2019;ll often ask yourself and it&amp;#x2019;s not always clear cut. Generally, you&amp;#x2019;ll use a PUT when you saving a document at a certain location or in a collection
  46. and POST when you want the application to decide where to save the document.
  47. It&amp;#x2019;s not clear cut though, so use your best judgements. Just remember that when you PUT a document at a location that it already exists at, you should PUT the entire original document, otherwise you should use UPDATE.
  48. Here is an example of using POST to delete.
  49. This is much better, it&amp;#x2019;s semantically correct and shorter to boot!
  50. Next up, tunnelling all errors through 200 OK. This is one of my biggest beefs and something that&amp;#x2019;s caught me out as a consumer a couple of times now.
  51. Anyone recognise this? When consuming the API of my wife, I ask her, &amp;#x2018;Are you OK?&amp;#x2019; and she response with &amp;#x2018;Fine&amp;#x201D; which, in my head, is a 200 ok. http://www.flickr.com/photos/yourdon/2573762303/ - Ed Yourdon
  52. Or this? From my wifes point of view.
  53. The error I&amp;#x2019;m receiveing reflects the request I made. It&amp;#x2019;s not 200 OK not the droids you&amp;#x2019;re looking for. THAT would be confusing. http://www.flickr.com/photos/thunderchild5/225675773/
  54. THIS is the most confusing and downright useless response I ever received from a Telco provider I worked with in my last job. A 200 OK code, with a plain text header and an XML body...
  55. Which leads on nicely to response codes. There are many Response Codes that you can return which will provide the consumer with a much better idea of how to handle the body of the response. They fall broadly into five categories.
  56. 1** information codes eg: continue, switching protocols
  57. 2xx codes: 200 OK, 201 created, 202 accepted
  58. 3xx redirection: 303 moved, 304 not modified http://www.flickr.com/photos/duchamp/126115989/ - Duchamp
  59. 4xx codes: 404, 401 Unauthorised http://www.flickr.com/photos/thefangmonster/490423135/ - The fang monster
  60. 5xx codes. Really, the crux of the matter here is use response codes that are relevant to the response you are sending.
  61. A 200 OK is an appropriate response for a successful PUT request, but to really be on the ball...
  62. ... send a 201 created!
  63. You can also make up your own codes, if the standard ones really don&amp;#x2019;t cut it.
  64. You can also make up your own codes.
  65. One of the greatest benefits of using HTTP is caching. However, HTTP caching is complex and scary. You should use it where you can and encourage your clients to make use of ...
  66. http://www.flickr.com/photos/epsos/4582789354/ - epSos.de
  67. ETags
  68. ETags are sent with the header and are a unique representation of that resource at that time. Collision-resistant has functions should be used to generate an etag, which is sent to the client. the client stores caches the etag along with the rest of the response, but the next time it makes a request to the URI, it sends an if-none-match header, which contains the original etag. The server will compare the two and, if nothing has changed, send a 304 (Can anyone tell me what a 304 is?) (Not Modified), otherwise, it will respond with the new data. More about caching is outside of the scope of this prez, talk to me afterwards if you want to know more (although, I don&apos;t know much more!).
  69. Cookies, delicious right? http://www.flickr.com/photos/projector/2092517108/ By allie pasquier
  70. Don&apos;t do it. If you have to, don&apos;t put server state data in them and don&apos;t authenticate with them. I have no idea yet how local storage will affect how I develop an API. http://www.flickr.com/photos/nickstone333/3135320160/ nickstone333
  71. What is hypermedia?
  72. What is hypermedia? Hypermedia is the sequel to Hypertext. Hypermedia includes audio, images, text and links. http://www.crystalxp.net/galerie/en.id.3751-bagg-a-png.htm
  73. HATEOAS: You should be able to access your API from a single URI and be able to traverse the entire API by just knowing the one URI. If you forget this, you&apos;re not taking advantage of one of the core concepts of REST. Your API is now self-documenting and can never be out of date. For example, what a consumer does:&amp;#xA0; GET: /users/MikePearce (assuming it&apos;s not cached) the API should return user information about me, but also information about how to modify me, how to delete me and links to other collections that have something to do with me. It should really also return a number of fixed URIs for adding collections. Or should it? That&apos;s one way of doing it, another way would be to publish one URI which lists all the features of the API and the URIs that you can access them with. Perhaps the endpoint as a start? Most clients will construct their own URIs, but mostly because they&apos;re never given any links to follow from the API in the first place! You can change this!
  74. So, as always there are grey areas. The lack of any standards or an RFC for REST means that there&apos;s often areas of the discipline which, for some, offer the opportunity for wiggle room. The first of these, which you will see debated frequently (and there&apos;s some great discussions on Stack Overflow) is... http://www.flickr.com/photos/rdrcollection/116454033/ Rodney Ramsey
  75. As with anything SAAS, your API will change over time and this means that some of your URIs may change. Now, the URI is the most prominent part of a RESTful API. It is something the users will use forever. It is a long term commitment to the user, so you have to get it right first time. However, there might be times when you absolutely have to change the way something works. For example, your initial design decision to make the URIs human readable means you might end up with a request like this:
  76. But, you&apos;ve now decided that you&apos;d be better off requesting the user from their ID.
  77. While less human readable, the margin for error is less. However, now all your consumers and clients are unable to query for both. You could program your API to look for strings AS WELL as integers, but it&apos;s going to get messy quickly. So, the best bet is to version. I&apos;ll explain a couple of methods for versioning, but you should decide what is best for you.
  78. 3. No versioning at all (but with a &apos;sunset&apos; period) (This is more difficult if the clients consuming your API are paying for it, or don&apos;t move very quickly, hence this becomes business decision, not a technical one.
  79. Another grey area, but this one only really has two choices. How does your client request particular document type? http://www.flickr.com/photos/turatti/4526352835/ jaci xIII
  80. You either use the .extension style...
  81. or send Accept headers with your request. You should bare in mind though that some servers WILL cache old accept headers or, in some instances, completely ignore your Accept headers. So it&amp;#x2019;s probably safer to use .extensions
  82. Summary.
  83. Don&amp;#x2019;t use get and post for everything. There ARE other verbs to apply to your nouns.
  84. Use appropriate error codes. If it&amp;#x2019;s an error, it&amp;#x2019;s not 200 OK (unless you were expecting and error code and 200 OK IS an error...)
  85. Use appropriate response codes. A 201 created or 202 accepted is preferable to a 200 OK after a mutation.
  86. Be responsible with caching. Suppy clients with an expiry time for the data you suppy and also encourage them to use etags
  87. Only use cookies if you really have to and make sure they contain stateless data. Prefer HTTP Auth over cookie auth if you can.
  88. Hate Oars, or, remember to provide links to other relevant parts of the API with your response. You can also provide a directory of URIs at your end point if you like.
  89. Versioning is totally up to you, there are a few options, it depends on you and your clients&amp;#x2019; needs.
  90. Use &amp;#x201C;dot&amp;#x201D; extensions or an Accept header, perhaps even both for those proxies which don&amp;#x2019;t behave themselves.
  91. Which leads on nicely to response codes. There are many Response Codes that you can return which will provide the consumer with a much better idea of how to handle the body of the response. They fall broadly into five categories.
  92. My name is Mike Pearce, this is my avatar, you&amp;#x2019;ll see it liberally splashed about on various social networks.