NEPHP '13: Pragmatic API Development

Andrew Curioso
Andrew CuriosoVP Engineering at MyVBO
Andrew Curioso
Twitter: @AndrewCurioso
#nephp
Pragmatic API Development
Andrew Curioso
What is an API?
● Application Programming Interface
● Web Service
● Contract
Business Case
● Mobile API First
Business Case
● Multiple Devices
Your API
Become a Platform
● Internal
– Multi-platform
– Scalable
● Semi-Public
– Partner Integration
● Public
– Everything+
– Growth
● Mashups
● Innovation
● Evangelism
– “The Platform Play”
Types of APIs
● Representation StateTransfer (REST)
● Remote Procedure Call (RPC)
● Realtime Streaming
What is REST?
● Nouns
● Verbs
● HTTP is inherently RESTful
Why REST
● Intuitive
● Easy to implement in PHP
● Widely accepted
Nouns
● Resources
– Blog post
– User
– Etc.
● Unique URIs
– Example: http://www.example.com/users/1234.json
Verbs
● 5 most common
– GET
– POST
– PUT
– DELETE
– HEAD
Verbs
● Uses
– GET – Read data
– POST and PUT write data
– DELETE and POST delete data
CSRF
● Cross Site Request Forgery
● Vectors:
– Embedded resources (<img>, <script>, etc)
– Hidden forms
security
CSRF
● Never edit data with GET
– Ajax Same origin policy→
● Forms
– Single use tokens
– Referrer check
security
Response Formats
● Json
– Very common for REST APIs
– Simple
– Fast
– Multi-platform
Response Formats
● JsonP
– P Padding→
– Allows reading data cross origin
– GET only
Response Formats
● XML
– Heavy and verbose
– Strictly typed
– Lots of existing tools
Response Formats
● Text
– Json / JsonP
– XML
– HTML
– YAML
– CSV
– Serialized PHP
– Etc.
● Binary
– Microsoft Excel
– PDF
– JPG / PNG / GIF
– MP3
– Etc.
Status Codes
● Success
– 200 OK
– 201 Created
– 301 Permanent Redirect
– 302 Found
– 303 See Other
Status Codes
● Error
– 401 Unauthorized
– 402 Payment Required
– 403 Forbidden
– 404 Not Found
– 405 Method NotAllowed
– 409 Conflict
– 410 Gone
– 500 Internal Server Error
– 501 Not Implemented
– 503 Service Unavailable
Status Codes
● Novelty
– 418 I Am ATeapot
– 415 Unavailable For Legal Reasons
Putting it together
● Getting
– Anything but GET
● 405 Method Not Allowed
– Resource not found
● 404 Not Found
– Success
● 200 OK
– Moved
● 301 Permanent Redirect or 302 Found
Putting it together
● Adding
– Anything but POST
● 405 Method Not Allowed
– Resource already existed
● 303 See Other
– Success
● 201 Created
– Error
● 500 Internal Server Error with description
Putting it together
● Editing
– Anything but PUT or POST
● 405 Method Not Allowed
– Resource does not exist
● 404 Not Found
– Success
● 200 OK
– Error
● 500 Internal Server Error with description
Putting it together
● Deleting
– Anything but DELETE or POST
● 405 Method Not Allowed
– Resource does not exist
● 404 Not Found
– Success
● 200 OK or 204 No Content
– Error
● 500 Internal Server Error with description
Putting it together
● Everything
– Not logged in
● 401 Unauthorized
– Logged in but permission denied
● 403 Forbidden
Putting it together
● Why POST or DELETE/PUT
– Client support
– _method=VERB
● /users.json?_method=POST
Example
● Past bin
● Simple
– No security
Example
● Making it RESTful
1) Identify nouns
2) Write down URI structure
3) Map verbs to the URIs
Example
● GET /documents.json
● POST /documents.json
● GET /documents/{id}.json
● DELETE /documents/{id}.json
● PUT /documents/{id}.json
HATEOAS
● Hypermedia as the Engine of Application
State
– Next state
– Content Negotiation
● Accepts header
Versioning
● URI
● Custom header
● Accepts header
Pagination
● Meta info
– URI to next/prev page (HATEOAS)
– Total count
– Current page
● Methods
– Header
– Document
Errors
● Same format
● Descriptive
{ "error" : { "code" : 404,
"description" : "The resource could not be found",
"name" : "Not Found"
} }
Testing
● GET Web Browser→
● OS X / Linux
– curl
– Example:
curl -X DELETE “
http://www.example.com/document/123.json”
● Automated UnitTests
Authentication
● Who am I?
● Types:
– Basic
– Digest
– OAuth 1 & 2 – No 3rd
party password sharing!
– Cookies
– API keys
● 401 Unauthorized
Authorization
● Can I do that?
● 403 Forbidden
Documentation
● Vocabularies / schemas
● Examples:
– Input
– Output
– Code
● Feedback
● WSDL 2.0
OtherTypes
● RPC
● Streaming
Checklist
✔ Design schema upfront
✔ Identify nouns
✔ Design URI structure
✔ Errors in same format
✔ Proper status codes
✔ Server-side validation
✔ Testing
✔ Documentation
Predictions
● Internet ofThings
● API Economy
● Success
Andrew Curioso
 Contact:
 www.AndrewCurioso.com/contact
 @AndrewCurioso onTwitter
1 of 41

Recommended

JSON API: Não reinvente a roda by
JSON API: Não reinvente a rodaJSON API: Não reinvente a roda
JSON API: Não reinvente a rodaPedro Cavalheiro
120 views19 slides
JSON-LD by
JSON-LDJSON-LD
JSON-LD名辰 洪
869 views41 slides
Web of data by
Web of dataWeb of data
Web of dataYves Raimond
1.3K views31 slides
PNWDS 2013- Restful development in Drupal 7/8 by
PNWDS 2013- Restful development in Drupal 7/8PNWDS 2013- Restful development in Drupal 7/8
PNWDS 2013- Restful development in Drupal 7/8Johannes Schmidt
1.4K views29 slides
Building WatchKit Applications by
Building WatchKit ApplicationsBuilding WatchKit Applications
Building WatchKit ApplicationsJean-Luc David
1.7K views22 slides
Tune hadoop by
Tune hadoopTune hadoop
Tune hadoopJason Shao
6K views14 slides

More Related Content

Viewers also liked

Confoo Developing for Wearables by
Confoo   Developing for WearablesConfoo   Developing for Wearables
Confoo Developing for WearablesJean-Luc David
1.6K views20 slides
Innovation & Business Acquisitions of Smart Security by
Innovation & Business Acquisitions of Smart SecurityInnovation & Business Acquisitions of Smart Security
Innovation & Business Acquisitions of Smart SecurityJean-Luc David
1.6K views26 slides
RightCycle by
RightCycleRightCycle
RightCycleJean-Luc David
1.1K views10 slides
Intro to HTTP and Node.js by
Intro to HTTP and Node.jsIntro to HTTP and Node.js
Intro to HTTP and Node.jsJean-Luc David
809 views12 slides
Introduction to MongoDB by
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJean-Luc David
852 views20 slides
Venture For Canada - Growing Your Startup by
Venture For Canada - Growing Your StartupVenture For Canada - Growing Your Startup
Venture For Canada - Growing Your StartupJean-Luc David
9.5K views22 slides

Viewers also liked(18)

Confoo Developing for Wearables by Jean-Luc David
Confoo   Developing for WearablesConfoo   Developing for Wearables
Confoo Developing for Wearables
Jean-Luc David1.6K views
Innovation & Business Acquisitions of Smart Security by Jean-Luc David
Innovation & Business Acquisitions of Smart SecurityInnovation & Business Acquisitions of Smart Security
Innovation & Business Acquisitions of Smart Security
Jean-Luc David1.6K views
Venture For Canada - Growing Your Startup by Jean-Luc David
Venture For Canada - Growing Your StartupVenture For Canada - Growing Your Startup
Venture For Canada - Growing Your Startup
Jean-Luc David9.5K views
Writing Mirror API and Native Apps for Google Glass by Jean-Luc David
Writing Mirror API and Native Apps for Google GlassWriting Mirror API and Native Apps for Google Glass
Writing Mirror API and Native Apps for Google Glass
Jean-Luc David13.6K views
Lessons from the Trenches: Building an API-Centric Architecture by WSO2
Lessons from the Trenches: Building an API-Centric ArchitectureLessons from the Trenches: Building an API-Centric Architecture
Lessons from the Trenches: Building an API-Centric Architecture
WSO21.7K views
Venture For Canada - Growth Hacking by Jean-Luc David
Venture For Canada - Growth HackingVenture For Canada - Growth Hacking
Venture For Canada - Growth Hacking
Jean-Luc David2.7K views
Venture For Canada - Growth Marketing by Jean-Luc David
Venture For Canada - Growth MarketingVenture For Canada - Growth Marketing
Venture For Canada - Growth Marketing
Jean-Luc David886 views
Startup Product Management - Execution by Jean-Luc David
Startup Product Management - ExecutionStartup Product Management - Execution
Startup Product Management - Execution
Jean-Luc David13.1K views
Startup Product Management - Analytics by Jean-Luc David
Startup Product Management - AnalyticsStartup Product Management - Analytics
Startup Product Management - Analytics
Jean-Luc David1.5K views
Code Retreat by Ben Morris
Code RetreatCode Retreat
Code Retreat
Ben Morris387 views
NEPHP '12: Create a RESTful API by Andrew Curioso
NEPHP '12: Create a RESTful APINEPHP '12: Create a RESTful API
NEPHP '12: Create a RESTful API
Andrew Curioso3K views
Mike Krieger - A Brief, Rapid History of Scaling Instagram (with a tiny team) by Jean-Luc David
Mike Krieger - A Brief, Rapid History of Scaling Instagram (with a tiny team)Mike Krieger - A Brief, Rapid History of Scaling Instagram (with a tiny team)
Mike Krieger - A Brief, Rapid History of Scaling Instagram (with a tiny team)
Jean-Luc David1K views
Developing For Wearables - Lessons Learned & Best Practices by Jean-Luc David
Developing For Wearables - Lessons Learned & Best PracticesDeveloping For Wearables - Lessons Learned & Best Practices
Developing For Wearables - Lessons Learned & Best Practices
Jean-Luc David38.5K views
あなたのチームの「いい人」は機能していますか? by Minoru Yokomichi
あなたのチームの「いい人」は機能していますか?あなたのチームの「いい人」は機能していますか?
あなたのチームの「いい人」は機能していますか?
Minoru Yokomichi169.7K views

Similar to NEPHP '13: Pragmatic API Development

Rest api-basic by
Rest api-basicRest api-basic
Rest api-basicAmila Sampath
145 views17 slides
Principles of building effective REST API by
Principles of building effective REST APIPrinciples of building effective REST API
Principles of building effective REST APIGeorgy Podsvetov
1.1K views56 slides
OpenTravel Advisory Forum 2012 REST XML Resources by
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Alliance
3.5K views24 slides
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer... by
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...Grand Parade Poland
484 views23 slides
Web API Test Automation Using Frisby & Node.js by
Web API Test Automation Using Frisby  & Node.jsWeb API Test Automation Using Frisby  & Node.js
Web API Test Automation Using Frisby & Node.jsHo Chi Minh City Software Testing Club
1.6K views30 slides
Web API Test Automation using Frisby & Node.js by
Web API Test Automation using Frisby  & Node.jsWeb API Test Automation using Frisby  & Node.js
Web API Test Automation using Frisby & Node.jsChi Lang Le Vu Tran
382 views30 slides

Similar to NEPHP '13: Pragmatic API Development(20)

Principles of building effective REST API by Georgy Podsvetov
Principles of building effective REST APIPrinciples of building effective REST API
Principles of building effective REST API
Georgy Podsvetov1.1K views
OpenTravel Advisory Forum 2012 REST XML Resources by OpenTravel Alliance
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Alliance3.5K views
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer... by Grand Parade Poland
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Confer...
Web Services Testing by DataArt
Web Services TestingWeb Services Testing
Web Services Testing
DataArt390 views
WebCamp: Developer Day: Принципы построения эффективного REST API - Георгий П... by GeeksLab Odessa
WebCamp: Developer Day: Принципы построения эффективного REST API - Георгий П...WebCamp: Developer Day: Принципы построения эффективного REST API - Георгий П...
WebCamp: Developer Day: Принципы построения эффективного REST API - Георгий П...
GeeksLab Odessa515 views
Pragmatic REST APIs by amesar0
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
amesar05.4K views
rest3d Web3D 2014 by Remi Arnaud
rest3d Web3D 2014rest3d Web3D 2014
rest3d Web3D 2014
Remi Arnaud2.7K views
Webservices Overview : XML RPC, SOAP and REST by Pradeep Kumar
Webservices Overview : XML RPC, SOAP and RESTWebservices Overview : XML RPC, SOAP and REST
Webservices Overview : XML RPC, SOAP and REST
Pradeep Kumar28.7K views
A Deep Dive into RESTful API Design Part 2 by VivekKrishna34
A Deep Dive into RESTful API Design Part 2A Deep Dive into RESTful API Design Part 2
A Deep Dive into RESTful API Design Part 2
VivekKrishna3490 views
RESTful for opentravel.org by HP by Roni Schuetz
RESTful for opentravel.org by HPRESTful for opentravel.org by HP
RESTful for opentravel.org by HP
Roni Schuetz2.8K views
REST Api Tips and Tricks by Maksym Bruner
REST Api Tips and TricksREST Api Tips and Tricks
REST Api Tips and Tricks
Maksym Bruner444 views
nguyenhainhathuy-building-restful-web-service by hazzaz
nguyenhainhathuy-building-restful-web-servicenguyenhainhathuy-building-restful-web-service
nguyenhainhathuy-building-restful-web-service
hazzaz905 views
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w... by Nguyen Duc Phu
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Nguyen Duc Phu1.1K views

Recently uploaded

WRN_Corporate_Presentation_Dec_2023.pdf by
WRN_Corporate_Presentation_Dec_2023.pdfWRN_Corporate_Presentation_Dec_2023.pdf
WRN_Corporate_Presentation_Dec_2023.pdfSandyNoyes
17 views57 slides
Investor Presentation by
Investor Presentation Investor Presentation
Investor Presentation TeckResourcesLtd
236 views28 slides
Corporate Presentation Probe Gold Dec 2023.pdf by
Corporate Presentation Probe Gold Dec 2023.pdfCorporate Presentation Probe Gold Dec 2023.pdf
Corporate Presentation Probe Gold Dec 2023.pdfProbe Gold
44 views17 slides
Collective Mining - November 2023 by
Collective Mining - November 2023Collective Mining - November 2023
Collective Mining - November 2023CollectiveMining1
156 views29 slides
Qi House Holdings Limited: Bubble by
Qi House Holdings Limited: BubbleQi House Holdings Limited: Bubble
Qi House Holdings Limited: BubbleShion Kib
7 views1 slide
Collective Mining - November 2023 by
Collective Mining - November 2023Collective Mining - November 2023
Collective Mining - November 2023CollectiveMining1
14 views29 slides

Recently uploaded(9)

WRN_Corporate_Presentation_Dec_2023.pdf by SandyNoyes
WRN_Corporate_Presentation_Dec_2023.pdfWRN_Corporate_Presentation_Dec_2023.pdf
WRN_Corporate_Presentation_Dec_2023.pdf
SandyNoyes17 views
Corporate Presentation Probe Gold Dec 2023.pdf by Probe Gold
Corporate Presentation Probe Gold Dec 2023.pdfCorporate Presentation Probe Gold Dec 2023.pdf
Corporate Presentation Probe Gold Dec 2023.pdf
Probe Gold44 views
Qi House Holdings Limited: Bubble by Shion Kib
Qi House Holdings Limited: BubbleQi House Holdings Limited: Bubble
Qi House Holdings Limited: Bubble
Shion Kib7 views
2311_presentation materials_en_slideshare.pdf by sansanir
2311_presentation materials_en_slideshare.pdf2311_presentation materials_en_slideshare.pdf
2311_presentation materials_en_slideshare.pdf
sansanir19 views
Nicola Mining Inc. Corporate Presentation November 2023 by nicola_mining
Nicola Mining Inc. Corporate Presentation November 2023Nicola Mining Inc. Corporate Presentation November 2023
Nicola Mining Inc. Corporate Presentation November 2023
nicola_mining48 views

NEPHP '13: Pragmatic API Development

Editor's Notes

  1. Thank you _____________ Today I’m going to be talking about creating a RESTful API with PHP. Not just any RESTful API, but an Epic one. &amp;lt;number&amp;gt;