Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
API Antipatterns
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Mike Pearce
March 26, 2012
Technology
250
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
API Antipatterns
Everyone *knows* how to build an API. This document describes how to NOT build one.
Mike Pearce
March 26, 2012
More Decks by Mike Pearce
See All by Mike Pearce
Being Agile
mikepearce
9
4.6k
How Big Is It? A guide to agile estimation and planning
mikepearce
5
910
Effective User Stories
mikepearce
2
260
Thimbl
mikepearce
1
160
UX for Developers
mikepearce
2
330
The Shu Ha Ri of Agile
mikepearce
1
650
The Anatomical Dissection of a Sprint Backlog
mikepearce
1
310
Other Decks in Technology
See All in Technology
AWSシリコン最前線 〜AI時代のチップ選択を読み解く〜
htokoyo
2
580
AIエージェントが名古屋の猛暑からあなたを守る
happysamurai294
0
110
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
10倍の生産性を実現するAI駆動並列エージェントのすべて
kumaiu
5
1.4k
自宅LLMの話
jacopen
1
520
Kubernetesにおける学習基盤とLLMOpsの概要
ry
1
290
MCP Appsを作ってみよう
iwamot
PRO
4
610
AAIFに入ってみた ~内から見えるコミュニティ動向~
sato4
0
190
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
2k
Snowflakeと仲良くなる第一歩
coco_se
4
460
失敗を経て、Harness Engineering で 大切にしたいことを考える / Learning from Failure: What Matters in Harness Engineering
bitkey
PRO
1
360
Bedrock AgentCore RuntimeでAuth0 Changelog調査AIをアップグレードした話
t5u8a5a
1
120
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Skip the Path - Find Your Career Trail
mkilby
1
150
Speed Design
sergeychernyshev
33
1.8k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Facilitating Awesome Meetings
lara
57
7k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
New Earth Scene 8
popppiees
3
2.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Optimizing for Happiness
mojombo
378
71k
Transcript
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
SONISPHERE @ Knebworth Flags should be banned a festivals!
Burritos: Best. Festival. Food. Ever.
None
Mike, Lee and Rog
SORRY
( ) HTTP REQUEST: That you get on with it...
Why am I here? REST
Why am I here? REST
Why am I here? REST Hah!
Why am I here? REST Huh?! ST
Do’s ✔
Do’s Dont’s ✔ ✘
Do’s Dont’s Whatevs.. ✔ ✘ ☠
But first... Some background
Who? Roy Fielding (the grandfather)
There!
Architectural Styles and the Design of Network- based Software Architectures
Can’t sleep? Read this...
None
A quick primer And now ...
REST != HTTP
REST != HTTP REST != The Web
REST
REST IS NOT
REST IS NOT HARD
REST IS NOT HARD Seriously!
Standards? We don’t need no steenkin’ standards!
MY CONSTRAINTS, LET ME SHOW YOU THEM
Some verbs...
Some nouns...
GET
PINT
PINT Please!
ANTI patterns Onto the main event
Overuse of ...
GET
None
Overuse of GET and POST or, GET/POST tunnelling.
None
None
BAD http://api.flickr.com/services/ rest/?method= flickr.photos.people.add &api_key=nnn&photo_id=yyy&u ser_id=xxx GET:
PUT: /user/MikePearce api_key=moo& age=33& size=medium& power=flight GOOD
PUT or POST? ASIDE PUT: /users/MikePearce PUT: /links/google PUT: /articles/100805/putorpost
PUT or POST? ASIDE POST: /documents/save name=styleguide.css& category=design
PUT or POST? ASIDE PUT when the resource will live
at the target URI POST when you want the server to handle the location of the resource.
POST: /dostuff/ user=MikePearce& action=delete& api_key=moo& token=quack& mode=3 BAD
GOOD DELETE: /user/MikePearce Wait! What? Why!?
Tunneling Errors through 200 OK?
Are you OK? I’m fine! Great! A 200 OK!
I’m fine! Are you OK? ARGGHH! He doesn’t understand me!
Great! A 200 OK!
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> </response> What am I supposed to do with this?
RESPONSE CODES Which leads me nicely to...
IE has failed Informational
Success FTW!1
Redirection
Client Error (you try illustrating client error!)
Server Error It’s 1am. I can’t find an image for
server error.
HTTP/1.1 200 OK PUT: /user/MikePearce Meh..
HTTP/1.1 201 CREATED PUT: /user/MikePearce Huzzah!
HTTP/1.1 418 GET: /whatareyou
HTTP/1.1 418 I’m a teapot GET: /whatareyou This one is
real1!!
Caching
None
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 Him again. Prolific bastard.
GET: /user/MikePearce GET: /user/66
GET: /v1/user/MikePearce 1. Versioning with the URI GET: /v2/user/66
GET: /user/66 2. Not versioning the primary URI GET: /v1/user/MikePearce
GET: /user/66 3. No versioning
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 MARY Phew!
Overuse of GET and POST or, GET/POST tunnelling.
Tunneling Errors through 200 OK?
RESPONSE CODES Which leads me nicely to...
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 questions? (that I can answer!)
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
Mike Pearce
[email protected]
mikepearce.net twtitter.com/mikepearce Thanks!