api pain points
TRANSCRIPT
![Page 1: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/1.jpg)
API PAIN-POINTSGETTING THINGS WRONG FOR FUN AND PROFIT
@PHILSTURGEON #PHPCAPETOWN14
![Page 2: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/2.jpg)
![Page 3: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/3.jpg)
![Page 4: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/4.jpg)
![Page 5: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/5.jpg)
![Page 6: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/6.jpg)
![Page 7: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/7.jpg)
![Page 8: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/8.jpg)
![Page 9: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/9.jpg)
![Page 10: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/10.jpg)
![Page 11: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/11.jpg)
ARCHITECTUREOLD SCHOOL
![Page 12: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/12.jpg)
![Page 13: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/13.jpg)
http://girlsgotsole.com/blog/thankful-thursday-rest-days/
![Page 14: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/14.jpg)
DATABASE SEEDINGLEAVE YOUR CUSTOMERS ALONE
![Page 15: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/15.jpg)
ENDPOINT THEORYNAMING THINGS IS HARD
![Page 16: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/16.jpg)
PLURAL V SINGULAR?CONSISTENCY IS KING
/user/23
/user
s
![Page 17: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/17.jpg)
PLURAL V SINGULAR?CONSISTENCY IS KING
/opportunity/
43
/opportunitie
s
![Page 18: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/18.jpg)
PLURAL V SINGULAR?CONSISTENCY IS KING
/places/places/12/places/12/checkins/places/12/checkins/34/checkins/34
![Page 19: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/19.jpg)
NO NEED FOR SEOQUERY STRINGS ARE FINE
/users/active/true
/users?active=true
![Page 20: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/20.jpg)
AUTO-INCREMENT = BADCTRL + S YOUR WEBSITE
/checkins/
1/
checkins/2
/checkins/2369
…
/checkins/
3
![Page 21: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/21.jpg)
AUTO-INCREMENT = BADCTRL + S YOUR WEBSITE
https://github.com/zackkitzmiller/tiny-php
https://github.com/ramsey/uuid
![Page 22: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/22.jpg)
WHICH METHODSVERB SOUP
List GET /users Read GET /users/XUpdate PUT /users/XUpdate PATCH /users/XCreate POST /usersDelete DELETE /users/XImage PUT /users/X/imageImages POST /users/X/imagesFavorites GET /users/X/favoritesCheckins GET /users/X/checkins
![Page 23: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/23.jpg)
FORM PAYLOADSJUST SEND JSON
foo=something&bar[baz]=thing&bar[stuff]=junk&bar=true
23
![Page 24: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/24.jpg)
HACKY PAYLOADSNOT LIKE THAT
![Page 25: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/25.jpg)
REAL JSON PAYLOADSTHNX!
![Page 26: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/26.jpg)
![Page 27: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/27.jpg)
200 = OKOr deal with
Chuck
![Page 28: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/28.jpg)
2xx is all about success3xx is all about
redirection4xx is all about client
errors5xx is all about service
errors
![Page 29: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/29.jpg)
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
![Page 30: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/30.jpg)
SUPPLEMENT HTTP CODESWHAT HAPPENED
{"error": {
"type": "OAuthException", "message": "Session has expired at unix
time 1385243766. The current unix time is 1385848532"
}}
![Page 31: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/31.jpg)
SUPPLEMENT HTTP CODESWHAT HAPPENED
{"error": {
"type": "OAuthException","code": “ERR-1012“,
"message": "Session has expired at unix time 1385243766. The current unix time is 1385848532"
}}
![Page 32: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/32.jpg)
AUTHENTICATION STRATEGYHOW MUCH DO YOU CARE
HTTP Basic
HTTP Digest
OAuth 1.0a
OAuth 2.0
![Page 33: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/33.jpg)
OAUTH 2 CAN DO A LOTPASSWORDS, IMPLICIT, SOCIAL LOGINS…
![Page 34: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/34.jpg)
OAUTH 2.0
thephpleague.com
github.com/thephpleague/oauth2-server
![Page 35: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/35.jpg)
USE SSL
![Page 36: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/36.jpg)
LOLEXCEPT FOR…
![Page 37: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/37.jpg)
![Page 38: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/38.jpg)
![Page 39: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/39.jpg)
TRANSFORMERS… ASSEMBLE!
![Page 40: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/40.jpg)
FLEXIBLE RESPONSESSTOP YOUR IPHONE DEV COMPLAINING
GET /checkins/dsfXte ?
include=place,user,activity
![Page 41: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/41.jpg)
PAGINATEDATA GROWS FAST
{"data": [
...],"cursors": { "after": "MTI=", "next_url": "https://api.example.com/
places?cursor=MTI%3&number=12"
}}
![Page 42: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/42.jpg)
DEFINE A LIMIT RANGEPAGINATION DDOS
if ($limit < 1 || $limit > 100) {
$limit = 100;}
![Page 43: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/43.jpg)
![Page 44: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/44.jpg)
AUTOMATE TESTINGIF YOU LOVE YOUR JOB
http://www.engineersgotblued.com/
![Page 45: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/45.jpg)
PHPUNIT + BEHAT
http://www.bil-jac.com/bestfriendsclub.php
![Page 46: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/46.jpg)
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 """
![Page 47: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/47.jpg)
Scenario: Try to find an invalid checkin
When I request "GET /checkins/nope"
Then I get a "404" response
![Page 48: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/48.jpg)
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
![Page 50: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/50.jpg)
![Page 51: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/51.jpg)
VERSIONING/V1/DOESNT COUNT
https://api.example.com/v1/places
![Page 52: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/52.jpg)
VERSIONING/V1/DOESNT COUNT
https://api-v1.example.com/places
![Page 53: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/53.jpg)
VERSIONING/V1/DOESNT COUNT
Accept: application/vnd.com.example.api-v1+json
Accept: application/vnd.com.example.api-v2+json
![Page 54: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/54.jpg)
VERSIONING/V1/DOESNT COUNT
Accept: application/vnd.com.example.user-v2+json
Accept: application/vnd.com.example.user-v3+json
![Page 55: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/55.jpg)
VERSIONING/V1/DOESNT COUNT
Copy Facebook
Maybe?
THIS ONE TIME!
![Page 56: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/56.jpg)
EVERYTHING IS WRONGDONT BE THAT GUY
troyhunt.com/2014/02/your-api-versioning-is-wrong-which-is.html
![Page 57: Api pain points](https://reader035.vdocuments.mx/reader035/viewer/2022062514/557bf74ed8b42ab9388b47a4/html5/thumbnails/57.jpg)
leanpub.com/build-apis-you-wont-hate/c/CAPEMAN2014