SlideShare a Scribd company logo
1 of 57
API PAIN-POINTS
GETTING THINGS WRONG FOR FUN AND PROFIT
@PHILSTURGEON #PHPCAPETOWN14
ARCHITECTURE
OLD SCHOOL
http://girlsgotsole.com/blog/thankful-thursday-rest-days/
DATABASE SEEDING
LEAVE YOUR CUSTOMERS ALONE
ENDPOINT THEORY
NAMING THINGS IS HARD
PLURAL V SINGULAR?
CONSISTENCY IS KING
/user/23
/user
s
PLURAL V SINGULAR?
CONSISTENCY IS KING
/opportunity/43
/opportunities
PLURAL V SINGULAR?
CONSISTENCY IS KING
/places
/places/12
/places/12/checkins
/places/12/checkins/34
/checkins/34
NO NEED FOR SEO
QUERY STRINGS ARE FINE
/users/active/true
/users?active=tru
e
AUTO-INCREMENT = BAD
CTRL + S YOUR WEBSITE
/checkins/1
/checkins/2
/checkins/236
9
…
/checkins/3
AUTO-INCREMENT = BAD
CTRL + S YOUR WEBSITE
https://github.com/zackkitzmiller/tiny-php
https://github.com/ramsey/uuid
WHICH METHODS
VERB SOUP
List GET /users
Read GET /users/X
Update PUT /users/X
Update PATCH /users/X
Create POST /users
Delete DELETE /users/X
Image PUT /users/X/image
Images POST /users/X/images
Favorites GET /users/X/favorites
Checkins GET /users/X/checkins
FORM PAYLOADS
JUST SEND JSON
foo=something&bar[baz]=thi
ng
23
HACKY PAYLOADS
NOT LIKE THAT
REAL JSON PAYLOADS
THNX!
200 = OK
Or deal with Chuck
2xx is all about success
3xx is all about redirection
4xx is all about client errors
5xx is all about service errors
200 - Generic everything is OK
201 - Created something OK
202 - Accepted but is being processed async
400 - Bad Request (Validation?)
401 - Unauthorized
403 - Current user is forbidden
404 - That URL is not a valid route
405 - Method Not Allowed
410 - Data has been deleted, deactivated, suspended, etc
500 - Something unexpected happened and it is the APIs fault
503 - API is not here right now, please try again later
SUPPLEMENT HTTP CODES
WHAT HAPPENED
{
"error": {
"type": "OAuthException",
"message": "Session has expired at unix time
1385243766. The current unix time is 1385848532"
}
}
SUPPLEMENT HTTP CODES
WHAT HAPPENED
{
"error": {
"type": "OAuthException",
"code": “ERR-1012“,
"message": "Session has expired at unix time
1385243766. The current unix time is 1385848532"
}
}
AUTHENTICATION STRATEGY
HOW MUCH DO YOU CARE
HTTP Basic
HTTP Digest
OAuth 1.0a
OAuth 2.0
OAUTH 2 CAN DO A LOT
PASSWORDS, IMPLICIT, SOCIAL LOGINS…
OAUTH 2.0
thephpleague.com
github.com/thephpleague/oauth2-server
USE SSL
LOL
EXCEPT FOR…
TRANSFORMERS… ASSEMBLE!
FLEXIBLE RESPONSES
STOP YOUR IPHONE DEV COMPLAINING
GET /checkins/dsfXte
?include=place,user,activity
PAGINATE
DATA GROWS FAST
{
"data": [
...
],
"cursors": {
"after": "MTI=",
"next_url": "https://api.example.com/places
?cursor=MTI%3&number=12"
}
}
DEFINE A LIMIT RANGE
PAGINATION DDOS
if ($limit < 1 || $limit > 100) {
$limit = 100;
}
AUTOMATE TESTING
IF YOU LOVE YOUR JOB
http://www.engineersgotblued.com/
PHPUNIT + BEHAT
http://www.bil-jac.com/bestfriendsclub.php
Scenario: Find a merchant
When I request "GET
/moments/1"
Then I get a "200" response
And scope into the "data"
property
And the properties exist:
"""
id
…
created_at
Scenario: Try to find an invalid
checkin
When I request "GET
/checkins/nope"
Then I get a "404" response
Scenario:Wrong Arguments for user
follow
Given I have the payload:
"""
{"is_following": "foo"}
"""
When I request "PUT /users/1”
Then I get a "400" response
apiblueprint.org
VERSIONING
/V1/DOESNT COUNT
https://api.example.com/v1/places
VERSIONING
/V1/DOESNT COUNT
https://api-v1.example.com/places
VERSIONING
/V1/DOESNT COUNT
Accept: application/vnd.com.example.api-v1+json
Accept: application/vnd.com.example.api-v2+json
VERSIONING
/V1/DOESNT COUNT
Accept: application/vnd.com.example.user-v2+json
Accept: application/vnd.com.example.user-v3+json
VERSIONING
/V1/DOESNT COUNT
Copy Facebook
Maybe?
THIS ONE TIME!
EVERYTHING IS WRONG
DONT BE THAT GUY
troyhunt.com/2014/02/your-api-versioning-is-wrong-which-is.html
leanpub.com/build-apis-you-wont-hate/c/CAPEMAN2014

More Related Content

What's hot

YQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentationYQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentation
Korben00
 
Tasc workshop presentation
Tasc workshop presentationTasc workshop presentation
Tasc workshop presentation
valleraj
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
Abhay Sapru
 
Select * from internet
Select * from internetSelect * from internet
Select * from internet
markandey
 
Intro to the Internet & HTML
Intro to the Internet & HTMLIntro to the Internet & HTML
Intro to the Internet & HTML
chrisramey
 
Missing kids on you
Missing kids on youMissing kids on you
Missing kids on you
guest3fa681
 
النشاط الخامس
النشاط الخامسالنشاط الخامس
النشاط الخامس
Dina Reda
 

What's hot (19)

YQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentationYQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentation
 
Tasc workshop presentation
Tasc workshop presentationTasc workshop presentation
Tasc workshop presentation
 
SmartData Webinar Slides JSON-LD
SmartData Webinar Slides JSON-LD SmartData Webinar Slides JSON-LD
SmartData Webinar Slides JSON-LD
 
Yahoo is open to developers
Yahoo is open to developersYahoo is open to developers
Yahoo is open to developers
 
Diary of a Hack
Diary of a HackDiary of a Hack
Diary of a Hack
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Select * from internet
Select * from internetSelect * from internet
Select * from internet
 
How to connect social media with open standards
How to connect social media with open standardsHow to connect social media with open standards
How to connect social media with open standards
 
Hebrew Bible as Data: Laboratory, Sharing, Lessons
Hebrew Bible as Data: Laboratory, Sharing, LessonsHebrew Bible as Data: Laboratory, Sharing, Lessons
Hebrew Bible as Data: Laboratory, Sharing, Lessons
 
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
Helping Data Teams with Puppet / Puppet Camp London - Apr 13, 2015
 
How I built the demo's
How I built the demo'sHow I built the demo's
How I built the demo's
 
HoneyNet SOTM 29 - Linux Server Hack Analysis
HoneyNet SOTM 29 - Linux Server Hack AnalysisHoneyNet SOTM 29 - Linux Server Hack Analysis
HoneyNet SOTM 29 - Linux Server Hack Analysis
 
Syndicated content on your web pages
Syndicated content on your web pagesSyndicated content on your web pages
Syndicated content on your web pages
 
Re-using social media data
Re-using social media dataRe-using social media data
Re-using social media data
 
Intro to the Internet & HTML
Intro to the Internet & HTMLIntro to the Internet & HTML
Intro to the Internet & HTML
 
Missing kids on you
Missing kids on youMissing kids on you
Missing kids on you
 
Microformats and SEO
Microformats and SEOMicroformats and SEO
Microformats and SEO
 
Lisa wilkins visual resume
Lisa wilkins visual resume Lisa wilkins visual resume
Lisa wilkins visual resume
 
النشاط الخامس
النشاط الخامسالنشاط الخامس
النشاط الخامس
 

Similar to Api pain points

Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
Java EE 7 (Lyon JUG & Alpes JUG  - March 2014)Java EE 7 (Lyon JUG & Alpes JUG  - March 2014)
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchReal-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet Elasticsearch
Alexei Gorobets
 
2012 03 27_philly_jug_rewrite_static
2012 03 27_philly_jug_rewrite_static2012 03 27_philly_jug_rewrite_static
2012 03 27_philly_jug_rewrite_static
Lincoln III
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTful
goldoraf
 
Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)
Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)
Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)
Alessandro Nadalin
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)
True-Vision
 

Similar to Api pain points (20)

Api pain points
Api pain pointsApi pain points
Api pain points
 
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
Java EE 7 (Lyon JUG & Alpes JUG  - March 2014)Java EE 7 (Lyon JUG & Alpes JUG  - March 2014)
Java EE 7 (Lyon JUG & Alpes JUG - March 2014)
 
Communication is a Technical Skill
Communication is a Technical SkillCommunication is a Technical Skill
Communication is a Technical Skill
 
Don't screw it up! How to build durable API
Don't screw it up! How to build durable API Don't screw it up! How to build durable API
Don't screw it up! How to build durable API
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchReal-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet Elasticsearch
 
2012 03 27_philly_jug_rewrite_static
2012 03 27_philly_jug_rewrite_static2012 03 27_philly_jug_rewrite_static
2012 03 27_philly_jug_rewrite_static
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Hacking For Innovation
Hacking For InnovationHacking For Innovation
Hacking For Innovation
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
 
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
 Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data... Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTful
 
Introductions of Messaging bot 做聊天機器人
Introductions of Messaging bot 做聊天機器人Introductions of Messaging bot 做聊天機器人
Introductions of Messaging bot 做聊天機器人
 
UC2013 Speed Geeking: Intro to OAuth2
UC2013 Speed Geeking: Intro to OAuth2UC2013 Speed Geeking: Intro to OAuth2
UC2013 Speed Geeking: Intro to OAuth2
 
RefCard RESTful API Design
RefCard RESTful API DesignRefCard RESTful API Design
RefCard RESTful API Design
 
Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)
Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)
Don't screw it up: how to build durable web apis @ PHPDay 2014 in Verona (ITA)
 
Don't screw it up: how to build durable web apis
Don't screw it up: how to build durable web apisDon't screw it up: how to build durable web apis
Don't screw it up: how to build durable web apis
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)
 
Petr Dvořák: Mobilní webové služby pohledem iPhone developera
Petr Dvořák: Mobilní webové služby pohledem iPhone developeraPetr Dvořák: Mobilní webové služby pohledem iPhone developera
Petr Dvořák: Mobilní webové služby pohledem iPhone developera
 
- Webexpo 2010
- Webexpo 2010- Webexpo 2010
- Webexpo 2010
 

More from Phil Sturgeon

Why I &lt;3 Laravel 4
Why I &lt;3 Laravel 4Why I &lt;3 Laravel 4
Why I &lt;3 Laravel 4
Phil Sturgeon
 
Introduction to Fuel
Introduction to FuelIntroduction to Fuel
Introduction to Fuel
Phil Sturgeon
 
Running an Open-Source CodeIgniter project
Running an Open-Source CodeIgniter projectRunning an Open-Source CodeIgniter project
Running an Open-Source CodeIgniter project
Phil Sturgeon
 

More from Phil Sturgeon (8)

PHP-FIG: Past, Present and Future
PHP-FIG: Past, Present and FuturePHP-FIG: Past, Present and Future
PHP-FIG: Past, Present and Future
 
Become Master of Your Own Universe - DIBI 2013
Become Master of Your Own Universe - DIBI 2013Become Master of Your Own Universe - DIBI 2013
Become Master of Your Own Universe - DIBI 2013
 
Laravel and Composer
Laravel and ComposerLaravel and Composer
Laravel and Composer
 
Why I &lt;3 Laravel 4
Why I &lt;3 Laravel 4Why I &lt;3 Laravel 4
Why I &lt;3 Laravel 4
 
CodeIgniter 3.0
CodeIgniter 3.0CodeIgniter 3.0
CodeIgniter 3.0
 
Cms expo
Cms expoCms expo
Cms expo
 
Introduction to Fuel
Introduction to FuelIntroduction to Fuel
Introduction to Fuel
 
Running an Open-Source CodeIgniter project
Running an Open-Source CodeIgniter projectRunning an Open-Source CodeIgniter project
Running an Open-Source CodeIgniter project
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Api pain points