SlideShare une entreprise Scribd logo
1  sur  70
Télécharger pour lire hors ligne
9 — Web API Design
From Code to Product
gidgreen.com/course
Lecture 9
•  Introduction
•  REST
•  Data formats
•  Security
•  Maintenance
•  Documentation
•  Resources
From Code to Product Lecture 9 — Web API Design — Slide 2 gidgreen.com/course
Application Programming Interface
“a set of functions and procedures that
allow the creation of applications which
access the features or data of an operating
system, application, or other service.”
— Oxford English Dictionary
“An interface or go-between that enables a
software program to interact with other
software.” — Investopedia
From Code to Product Lecture 9 — Web API Design — Slide 3 gidgreen.com/course
Types of API
•  Programming language libraries, e.g. C
– malloc(), printf(), strcpy()
•  Operating systems, e.g. Android
–  findViewById(R.id.search).setText("");
•  Plug-in APIs, e.g. NPAPI for browsers
– NPError NP_Initialize(…)
•  Web APIs, e.g. Yahoo! BOSS
–  http://yboss.yahooapis.com/ysearch/web?q=API
From Code to Product Lecture 9 — Web API Design — Slide 4 gidgreen.com/course
Web APIs
•  Same infrastructure as websites
– Request—Response over HTTP
– Open and exposed to the world
•  Textual request/response
– URLs in, JSON/XML out (generally)
•  Many simply wrap web requests…
– e.g. search APIs, Twitter posting
•  …but many go far beyond
From Code to Product Lecture 9 — Web API Design — Slide 5 gidgreen.com/course
Example: Facebook Graph API
From Code to Product Lecture 9 — Web API Design — Slide 6 gidgreen.com/course
Amazon Product Advertising API
From Code to Product Lecture 9 — Web API Design — Slide 7 gidgreen.com/course
Twitter REST API
From Code to Product Lecture 9 — Web API Design — Slide 8 gidgreen.com/course
Growth in Web APIs
From Code to Product Lecture 9 — Web API Design — Slide 9 gidgreen.com/course
API Billionaires’ Club
From Code to Product Lecture 9 — Web API Design — Slide 10 gidgreen.com/course
http://blog.programmableweb.com/2012/05/23/
which-apis-are-handling-billions-of-requests-per-day/
Why offer an API?
•  Avoid (control) scraping
•  Develop partnerships
– “Business development 2.0”
•  New distribution channels
•  Increase revenue (if paid)
•  Externalize innovation
– Copy the best?
•  Customer lock-in through integration
From Code to Product Lecture 9 — Web API Design — Slide 11 gidgreen.com/course
Business questions
•  What is our goal for the API?
– How does it contribute to business?
•  Free vs paid?
– Revenue generation vs marketing
•  Who will use it?
– Aim at those developers’ success
•  What do they want to do with it?
– Can our competitors make use of it?
From Code to Product Lecture 9 — Web API Design — Slide 12 gidgreen.com/course
API-focused companies: Stripe
From Code to Product Lecture 9 — Web API Design — Slide 13 gidgreen.com/course
API-focused companies: Zencoder
From Code to Product Lecture 9 — Web API Design — Slide 14 gidgreen.com/course
API-only companies: SendGrid
From Code to Product Lecture 9 — Web API Design — Slide 15 gidgreen.com/course
API-only companies: Twilio
From Code to Product Lecture 9 — Web API Design — Slide 16 gidgreen.com/course
API vs licensing code
•  Better business model
– Recurring revenue (by usage)
– Suits small and large clients
•  Easier to maintain
– No need for “releases”
– Controlled environment
•  Keep control over IP
•  But it’s a serious operation
– Risk of downtime (SLAs?)
From Code to Product Lecture 9 — Web API Design — Slide 17 gidgreen.com/course
Lecture 9
•  Introduction
•  REST
•  Data formats
•  Security
•  Maintenance
•  Documentation
•  Resources
From Code to Product Lecture 9 — Web API Design — Slide 18 gidgreen.com/course
REST
•  Representational State Transfer
– Most popular design model for Web APIs
•  Entities (“resources”) = URLs
•  Actions = HTTP commands
– GET, POST, PUT, DELETE
•  Resources are self-descriptive
•  No hidden server-side state
•  (UI Principles applied to developers!)
From Code to Product Lecture 9 — Web API Design — Slide 19 gidgreen.com/course
HTTP request example
PUT /api/dogs/3 HTTP/1.1
Host: dog-db.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 21
Request data...
From Code to Product Lecture 9 — Web API Design — Slide 20 gidgreen.com/course
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
Content-Length: 94
Response data…
REST GET Example 1
GET http://dog-db.com/api/dogs
[
{ id:1, name:"Fido" },
{ id:2, name:"Rover" },
{ id:3, name:"Spot" },
{ id:4, name:"Fluffy" },
]
From Code to Product Lecture 9 — Web API Design — Slide 21 gidgreen.com/course
REST GET Example 2
GET http://dog-db.com/api/dogs/3
{
id:3,
name:"Spot",
dob:"2009-05-21",
type:"spaniel",
photo:"http://dog-db/images/…
From Code to Product Lecture 9 — Web API Design — Slide 22 gidgreen.com/course
Expressing relationships
{
id:3,
name:"Spot",
dob:"2009-05-21",
owner:{
id:16,
name:"Sam",
url:"http://dog-db.com/api/owners/16"
}
…
From Code to Product Lecture 9 — Web API Design — Slide 23 gidgreen.com/course
HTTP
command
Database
operation
/dogs /dogs/3
GET Read List all dogs Get dog details
POST Create Create new dog —
PUT Update — Update detail/s
DELETE Delete Delete all dogs Delete this dog
REST as CRUD
From Code to Product Lecture 9 — Web API Design — Slide 24 gidgreen.com/course
REST PUT Example
PUT http://dog-db/api/dogs/3
name=Fifi&type=poodle
{
id:3,
name:”Fifi",
dob:"2009-05-21",
type:”poodle”,
From Code to Product Lecture 9 — Web API Design — Slide 25 gidgreen.com/course
Rules for REST actions
•  GET does not change server state
– Allows caching, prefetching
– Like requesting web page
•  PUT and DELETE are “idempotent”
– Repeated calls don’t matter
•  POST can change server state each time
– Classic example: transfer money
– Like submitting web form
From Code to Product Lecture 9 — Web API Design — Slide 26 gidgreen.com/course
Choosing REST URLs
•  Stick to plural forms
– /dogs → /dogs/3 not /dog/3
•  Avoid abstractions
– /dogs/3 better than /entities/3
•  If multiple return types:
– /dogs/3?type=json
– /dogs/3.json
•  Consistency is king!
From Code to Product Lecture 9 — Web API Design — Slide 27 gidgreen.com/course
More URL best practices
•  Pagination of results
– ?start=20&count=10
•  Subset of fields
– ?fields=id,name,owner,type
•  API calls not on resources
– GET /api/search?q=...
– GET /api/convert?
from=km&to=inch&value=0.63
From Code to Product Lecture 9 — Web API Design — Slide 28 gidgreen.com/course
Other protocols
•  Simple Object Access Protocol (SOAP)
– XML-based + lots of extra cruft
– Hard to read and write manually
– Formalization and discovery via WSDL
•  XML-Remote Procedure Call (XML-RPC)
– Simpler precursor to SOAP
– Based on functions, e.g. getDogName()
•  Neither uses URLs for entities
From Code to Product Lecture 9 — Web API Design — Slide 29 gidgreen.com/course
Lecture 9
•  Introduction
•  REST
•  Data formats
•  Security
•  Maintenance
•  Documentation
•  Resources
From Code to Product Lecture 9 — Web API Design — Slide 30 gidgreen.com/course
Important data types
•  String
•  Number
•  Boolean
•  Date/time
•  Null/nil
•  Binary large objects (BLOBs)
•  Array = unlabeled ordered list
•  Object = labeled (ordered) list
From Code to Product Lecture 9 — Web API Design — Slide 31 gidgreen.com/course
Scalars
Extensible Markup Language (XML)
<dogs>
<dog id="3">
<name>Spot</name>
<age>7</age>
<type></type>
<owner id="16">
<name>Sam</name>
</owner>
<collar>true</collar>
</dog>
<dog id="4">
...
From Code to Product Lecture 9 — Web API Design — Slide 32 gidgreen.com/course
ü  User friendly
ü  Looks like HTML
⨯ Wordy
⨯ Elements vs
attributes
⨯ Implicit typing
⨯ "123"
⨯ Array of one
RSS 2.0 (see also: Atom)
<rss version="2.0">
<channel>
<title>Dog Tales</title>
<description>Stories about dogs</description>
<link>http://dog-tales.com/</link>
<item>
<title>Cat chasing</title>
<description>A dog ran after a cat</description>
<link>http://dog-tales.com/</link>
<pubDate>Thu, 09 May 2013 16:45:00 +0000</pubDate>
</item>
<item>
...
From Code to Product Lecture 9 — Web API Design — Slide 33 gidgreen.com/course
Javascript Object Notation (JSON)
[
{
id:3,
name:"Spot",
age:7,
type:null,
owner:{id:16,name:"Sam"},
collar:true,
},
{
id:4,
...
From Code to Product Lecture 9 — Web API Design — Slide 34 gidgreen.com/course
ü  Compact
ü  Explicit types
ü  [] vs {}
ü  Javascript-ish
ü  JSONP for
web access
⨯ Feels like
programming
Urlencoding
•  URL parameters
•  Multifield forms (PUT/POST)
From Code to Product Lecture 9 — Web API Design — Slide 35 gidgreen.com/course
http://dog-tales.com/
BLOBs (rich media)
•  Raw delivery
– Can’t be combined with other data
– For HTTP use MIME to identify
•  Provide URL (string)
– Separate request to retrieve
•  Base64 encoding
– Inflates size by 33%
– Standard method for web forms
From Code to Product Lecture 9 — Web API Design — Slide 36 gidgreen.com/course
Error reporting
•  Use HTTP response code
– Allow suppression, e.g. for Flash
•  Error in response:
{
http-code:401,
error-code:-329,
error-message:"Invalid API key",
error-help:"http://dog-db.com/docs
errors/-329.html”
From Code to Product Lecture 9 — Web API Design — Slide 37 gidgreen.com/course
HTTP response codes
From Code to Product Lecture 9 — Web API Design — Slide 38 gidgreen.com/course
HTTP code Meaning
200 OK
4xx Bad request (client’s fault)
5xx Failed request (server’s fault)
401 Unauthorized request
404 Resource not found
500 Internal error (bug)
503 Server overloaded
Lecture 9
•  Introduction
•  REST
•  Data formats
•  Security
•  Maintenance
•  Documentation
•  Resources
From Code to Product Lecture 9 — Web API Design — Slide 39 gidgreen.com/course
Simple HTTP Authentication
GET /api/dogs/?appID=29838&key=k234nb3bf89
Host: dog-db.com
GET /api/dogs/
Host: dog-db.com
Authorization: Basic QWxhZGRpbjpvcGc2FtZQ==
From Code to Product Lecture 9 — Web API Design — Slide 40 gidgreen.com/course
ü  Trivial for developers
⨯ Visible to intermediaries
ü  https can solve this
Signing API calls
•  Client and server share secret key
•  Signature is hash (one-way function) of:
– Request
– Parameters (alphabetical order)
– Secret key
•  Best practice: multiple keys per user
– Users can disable some applications
•  Problem: replay attacks
From Code to Product Lecture 9 — Web API Design — Slide 41 gidgreen.com/course
OAuth 1.0
•  Standard for digitally signing API calls
•  Permits delegation
– User grants temporary access to API for them
•  Prevents replay attacks
– Via ‘nonce’ = number used once
•  Popular industry standard
– Dropbox, Evernote, Flickr, Twitter
•  See also: OAuth 2.0
From Code to Product Lecture 9 — Web API Design — Slide 42 gidgreen.com/course
Rate limiting
•  Per IP address, but…
– Proxy networks e.g. Tor
– Temporary cloud instances
•  Per API key, but…
– Multiple key signups
•  Per queried entity
•  Based on (API) server load
•  Charging solves everything…
From Code to Product Lecture 9 — Web API Design — Slide 43 gidgreen.com/course
Final comments on security
•  Do not trust clients
– All input must be sanitized
•  Clients must store key
– So desktop/mobile apps hackable
•  You can’t take back data
– Limit scope of responses
•  Don’t reinvent the wheel
– Save developers time
From Code to Product Lecture 9 — Web API Design — Slide 44 gidgreen.com/course
Lecture 9
•  Introduction
•  REST
•  Data formats
•  Security
•  Maintenance
•  Documentation
•  Resources
From Code to Product Lecture 9 — Web API Design — Slide 45 gidgreen.com/course
Maintenance issues
•  Downtime
•  Versioning
•  Scaling
•  Monitoring
•  Logging
From Code to Product Lecture 9 — Web API Design — Slide 46 gidgreen.com/course
Downtime
•  Developers test then deploy
– When you go down, they go down
•  So avoid at all costs by:
– Monitoring
– Versioning
•  If unavoidable then:
– Do it on the weekend
– Give advanced notice
From Code to Product Lecture 9 — Web API Design — Slide 47 gidgreen.com/course
API status
From Code to Product Lecture 9 — Web API Design — Slide 48 gidgreen.com/course
Versioning
GET http://dog-db.com/api/v1/dogs/
•  Version at start of URL
•  v1 then v2 — no v1.1
– Makes compatibility clear
•  Maintain one version back
•  It’s still a failure
– Add URLs/parameters instead
From Code to Product Lecture 9 — Web API Design — Slide 49 gidgreen.com/course
Scaling
•  Usage volumes can surprise you
– You’re serving software, not people
– Small number of heavy users
– Very peaky traffic
•  Caching is your friend
•  Drop expensive requests under load
•  Slow response better than none
•  Separate domain: api.dog-db.com
From Code to Product Lecture 9 — Web API Design — Slide 50 gidgreen.com/course
Monitoring
•  Volume of API calls
•  Popular calls
•  Response time
•  Error rates
•  Active developers
– Hyperactive developers
•  Revenue (+indirect) vs costs
From Code to Product Lecture 9 — Web API Design — Slide 51 gidgreen.com/course
Monitoring made public
From Code to Product Lecture 9 — Web API Design — Slide 52 gidgreen.com/course
Logging
•  Log everything
– Incoming requests
– Outgoing response
– Response time
•  To enable…
– Bug resolution
– Abuse forensics
– Deeper (offline) analytics
From Code to Product Lecture 9 — Web API Design — Slide 53 gidgreen.com/course
Lecture 9
•  Introduction
•  REST
•  Data formats
•  Security
•  Maintenance
•  Documentation
•  Conclusion
From Code to Product Lecture 9 — Web API Design — Slide 54 gidgreen.com/course
Documentation
•  Reference
•  Examples
•  API explorer
•  Language libraries
•  Example apps
•  Discussion forum
•  (and support)
From Code to Product Lecture 9 — Web API Design — Slide 55 gidgreen.com/course
Reference: security
From Code to Product Lecture 9 — Web API Design — Slide 56 gidgreen.com/course
Reference: URLs
From Code to Product Lecture 9 — Web API Design — Slide 57 gidgreen.com/course
Reference: input parameters
From Code to Product Lecture 9 — Web API Design — Slide 58 gidgreen.com/course
For each input parameter
•  Name of parameter
•  Explanation/meaning
•  Possible values/range
•  Example values
•  Optional or required?
– Default value if optional
From Code to Product Lecture 9 — Web API Design — Slide 59 gidgreen.com/course
Reference: output fields
From Code to Product Lecture 9 — Web API Design — Slide 60 gidgreen.com/course
Reference: response codes
From Code to Product Lecture 9 — Web API Design — Slide 61 gidgreen.com/course
Examples
From Code to Product Lecture 9 — Web API Design — Slide 62 gidgreen.com/course
API explorer
From Code to Product Lecture 9 — Web API Design — Slide 63 gidgreen.com/course
Language libraries
From Code to Product Lecture 9 — Web API Design — Slide 64 gidgreen.com/course
ü  Developers
save time
ü  Get fewer bad
API calls
⨯ You must learn
many languages
⨯ Maintenance
Example apps
From Code to Product Lecture 9 — Web API Design — Slide 65 gidgreen.com/course
Discussion forum
From Code to Product Lecture 9 — Web API Design — Slide 66 gidgreen.com/course
Lecture 9
•  Introduction
•  REST
•  Data formats
•  Security
•  Maintenance
•  Documentation
•  Conclusion
From Code to Product Lecture 9 — Web API Design — Slide 67 gidgreen.com/course
Things to avoid
•  Lengthy signup process
•  Exposing raw/ugly data
•  Complex security model
•  Breaking backwards compatibility
•  Inaccurate documentation
•  Multi-call operations (“chatty APIs”)
•  Developer frustration
From Code to Product Lecture 9 — Web API Design — Slide 68 gidgreen.com/course
Books
From Code to Product Lecture 9 — Web API Design — Slide 69 gidgreen.com/course
Resources and services
From Code to Product Lecture 9 — Web API Design — Slide 70 gidgreen.com/course

Contenu connexe

Similaire à Web API Design 2013

API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsTom Johnson
 
Consuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL WebservicesConsuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL WebservicesEdwin Rojas
 
SharePoint for the .NET Developer
SharePoint for the .NET DeveloperSharePoint for the .NET Developer
SharePoint for the .NET DeveloperJohn Calvert
 
PaaS - google app engine
PaaS  - google app enginePaaS  - google app engine
PaaS - google app engineJ Singh
 
Upstream consultancy and Ceph RadosGW/S3 - Javier Munhoz
Upstream consultancy and Ceph RadosGW/S3 - Javier MunhozUpstream consultancy and Ceph RadosGW/S3 - Javier Munhoz
Upstream consultancy and Ceph RadosGW/S3 - Javier MunhozCeph Community
 
Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)
Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)
Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)Igalia
 
2013 - Back to the Future with Client/Server Development
2013 - Back to the Future with Client/Server Development 2013 - Back to the Future with Client/Server Development
2013 - Back to the Future with Client/Server Development Chris O'Connor
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan WrightSummit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan WrightAndrew Ly
 
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdfAstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdfFarHanWasif1
 
Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365Kashif Imran
 
Priyanka Pandit | Resume
Priyanka Pandit | ResumePriyanka Pandit | Resume
Priyanka Pandit | ResumePriyanka Pandit
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
API Sandbox: Empowering Developer Experience (DX)
API Sandbox: Empowering Developer Experience (DX)API Sandbox: Empowering Developer Experience (DX)
API Sandbox: Empowering Developer Experience (DX)Faisal Banaeamah
 
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionArabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionJasonRafeMiller
 
Introduction to CloudStack API
Introduction to CloudStack APIIntroduction to CloudStack API
Introduction to CloudStack APIKrunal Jain
 
2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open StandardsAPIsecure_ Official
 
Syllabus for Technical courses
Syllabus for Technical coursesSyllabus for Technical courses
Syllabus for Technical coursesMontek1Learning
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...Mark Leusink
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...Mark Roden
 

Similaire à Web API Design 2013 (20)

API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
Consuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL WebservicesConsuming GRIN GLOBAL Webservices
Consuming GRIN GLOBAL Webservices
 
SharePoint for the .NET Developer
SharePoint for the .NET DeveloperSharePoint for the .NET Developer
SharePoint for the .NET Developer
 
PaaS - google app engine
PaaS  - google app enginePaaS  - google app engine
PaaS - google app engine
 
Upstream consultancy and Ceph RadosGW/S3 - Javier Munhoz
Upstream consultancy and Ceph RadosGW/S3 - Javier MunhozUpstream consultancy and Ceph RadosGW/S3 - Javier Munhoz
Upstream consultancy and Ceph RadosGW/S3 - Javier Munhoz
 
Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)
Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)
Upstream Consultancy and Ceph RadosGW/S3 (AMTEGA Ceph Day 2018)
 
2013 - Back to the Future with Client/Server Development
2013 - Back to the Future with Client/Server Development 2013 - Back to the Future with Client/Server Development
2013 - Back to the Future with Client/Server Development
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan WrightSummit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
Summit Australia 2019 - PowerApp Portals - Andrew Ly & Lachlan Wright
 
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdfAstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
 
Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365
 
Priyanka Pandit | Resume
Priyanka Pandit | ResumePriyanka Pandit | Resume
Priyanka Pandit | Resume
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
API Sandbox: Empowering Developer Experience (DX)
API Sandbox: Empowering Developer Experience (DX)API Sandbox: Empowering Developer Experience (DX)
API Sandbox: Empowering Developer Experience (DX)
 
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, IntroductionArabidopsis Information Portal, Developer Workshop 2014, Introduction
Arabidopsis Information Portal, Developer Workshop 2014, Introduction
 
Introduction to CloudStack API
Introduction to CloudStack APIIntroduction to CloudStack API
Introduction to CloudStack API
 
2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards2022 APIsecure_Securing APIs with Open Standards
2022 APIsecure_Securing APIs with Open Standards
 
Syllabus for Technical courses
Syllabus for Technical coursesSyllabus for Technical courses
Syllabus for Technical courses
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 

Plus de gidgreen

The Secret Guide to Cloud Performance - Cloudlook
The Secret Guide to Cloud Performance - CloudlookThe Secret Guide to Cloud Performance - Cloudlook
The Secret Guide to Cloud Performance - Cloudlookgidgreen
 
Localization and Internationalization 2013
Localization and Internationalization 2013Localization and Internationalization 2013
Localization and Internationalization 2013gidgreen
 
Analytics and Optimization 2013
Analytics and Optimization 2013Analytics and Optimization 2013
Analytics and Optimization 2013gidgreen
 
Search Engine Visibility 2013
Search Engine Visibility 2013Search Engine Visibility 2013
Search Engine Visibility 2013gidgreen
 
Marketing for Startups 2013
Marketing for Startups 2013Marketing for Startups 2013
Marketing for Startups 2013gidgreen
 
Selling Advertising 2013
Selling Advertising 2013Selling Advertising 2013
Selling Advertising 2013gidgreen
 
Selling Products and Services 2013
Selling Products and Services 2013Selling Products and Services 2013
Selling Products and Services 2013gidgreen
 
User Interface Design 2013
User Interface Design 2013User Interface Design 2013
User Interface Design 2013gidgreen
 
User Interface Principles 2013
User Interface Principles 2013User Interface Principles 2013
User Interface Principles 2013gidgreen
 
The Software Entrepreneurship Process 2013
The Software Entrepreneurship Process 2013The Software Entrepreneurship Process 2013
The Software Entrepreneurship Process 2013gidgreen
 
Introduction to Software Products and Startups 2013
Introduction to Software Products and Startups 2013Introduction to Software Products and Startups 2013
Introduction to Software Products and Startups 2013gidgreen
 
Question2Answer - September 2012
Question2Answer - September 2012Question2Answer - September 2012
Question2Answer - September 2012gidgreen
 
Search Engine Visibility
Search Engine VisibilitySearch Engine Visibility
Search Engine Visibilitygidgreen
 
Marketing for Startups
Marketing for StartupsMarketing for Startups
Marketing for Startupsgidgreen
 
Analytics and Optimization
Analytics and OptimizationAnalytics and Optimization
Analytics and Optimizationgidgreen
 
Selling Products and Services
Selling Products and ServicesSelling Products and Services
Selling Products and Servicesgidgreen
 
Advertising as a Business Model
Advertising as a Business ModelAdvertising as a Business Model
Advertising as a Business Modelgidgreen
 
Localization and Internationalization
Localization and InternationalizationLocalization and Internationalization
Localization and Internationalizationgidgreen
 
User Interface Design
User Interface DesignUser Interface Design
User Interface Designgidgreen
 
User Interface Principles
User Interface PrinciplesUser Interface Principles
User Interface Principlesgidgreen
 

Plus de gidgreen (20)

The Secret Guide to Cloud Performance - Cloudlook
The Secret Guide to Cloud Performance - CloudlookThe Secret Guide to Cloud Performance - Cloudlook
The Secret Guide to Cloud Performance - Cloudlook
 
Localization and Internationalization 2013
Localization and Internationalization 2013Localization and Internationalization 2013
Localization and Internationalization 2013
 
Analytics and Optimization 2013
Analytics and Optimization 2013Analytics and Optimization 2013
Analytics and Optimization 2013
 
Search Engine Visibility 2013
Search Engine Visibility 2013Search Engine Visibility 2013
Search Engine Visibility 2013
 
Marketing for Startups 2013
Marketing for Startups 2013Marketing for Startups 2013
Marketing for Startups 2013
 
Selling Advertising 2013
Selling Advertising 2013Selling Advertising 2013
Selling Advertising 2013
 
Selling Products and Services 2013
Selling Products and Services 2013Selling Products and Services 2013
Selling Products and Services 2013
 
User Interface Design 2013
User Interface Design 2013User Interface Design 2013
User Interface Design 2013
 
User Interface Principles 2013
User Interface Principles 2013User Interface Principles 2013
User Interface Principles 2013
 
The Software Entrepreneurship Process 2013
The Software Entrepreneurship Process 2013The Software Entrepreneurship Process 2013
The Software Entrepreneurship Process 2013
 
Introduction to Software Products and Startups 2013
Introduction to Software Products and Startups 2013Introduction to Software Products and Startups 2013
Introduction to Software Products and Startups 2013
 
Question2Answer - September 2012
Question2Answer - September 2012Question2Answer - September 2012
Question2Answer - September 2012
 
Search Engine Visibility
Search Engine VisibilitySearch Engine Visibility
Search Engine Visibility
 
Marketing for Startups
Marketing for StartupsMarketing for Startups
Marketing for Startups
 
Analytics and Optimization
Analytics and OptimizationAnalytics and Optimization
Analytics and Optimization
 
Selling Products and Services
Selling Products and ServicesSelling Products and Services
Selling Products and Services
 
Advertising as a Business Model
Advertising as a Business ModelAdvertising as a Business Model
Advertising as a Business Model
 
Localization and Internationalization
Localization and InternationalizationLocalization and Internationalization
Localization and Internationalization
 
User Interface Design
User Interface DesignUser Interface Design
User Interface Design
 
User Interface Principles
User Interface PrinciplesUser Interface Principles
User Interface Principles
 

Dernier

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 DevelopmentsTrustArc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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...Drew Madelung
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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...apidays
 

Dernier (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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...
 

Web API Design 2013

  • 1. 9 — Web API Design From Code to Product gidgreen.com/course
  • 2. Lecture 9 •  Introduction •  REST •  Data formats •  Security •  Maintenance •  Documentation •  Resources From Code to Product Lecture 9 — Web API Design — Slide 2 gidgreen.com/course
  • 3. Application Programming Interface “a set of functions and procedures that allow the creation of applications which access the features or data of an operating system, application, or other service.” — Oxford English Dictionary “An interface or go-between that enables a software program to interact with other software.” — Investopedia From Code to Product Lecture 9 — Web API Design — Slide 3 gidgreen.com/course
  • 4. Types of API •  Programming language libraries, e.g. C – malloc(), printf(), strcpy() •  Operating systems, e.g. Android –  findViewById(R.id.search).setText(""); •  Plug-in APIs, e.g. NPAPI for browsers – NPError NP_Initialize(…) •  Web APIs, e.g. Yahoo! BOSS –  http://yboss.yahooapis.com/ysearch/web?q=API From Code to Product Lecture 9 — Web API Design — Slide 4 gidgreen.com/course
  • 5. Web APIs •  Same infrastructure as websites – Request—Response over HTTP – Open and exposed to the world •  Textual request/response – URLs in, JSON/XML out (generally) •  Many simply wrap web requests… – e.g. search APIs, Twitter posting •  …but many go far beyond From Code to Product Lecture 9 — Web API Design — Slide 5 gidgreen.com/course
  • 6. Example: Facebook Graph API From Code to Product Lecture 9 — Web API Design — Slide 6 gidgreen.com/course
  • 7. Amazon Product Advertising API From Code to Product Lecture 9 — Web API Design — Slide 7 gidgreen.com/course
  • 8. Twitter REST API From Code to Product Lecture 9 — Web API Design — Slide 8 gidgreen.com/course
  • 9. Growth in Web APIs From Code to Product Lecture 9 — Web API Design — Slide 9 gidgreen.com/course
  • 10. API Billionaires’ Club From Code to Product Lecture 9 — Web API Design — Slide 10 gidgreen.com/course http://blog.programmableweb.com/2012/05/23/ which-apis-are-handling-billions-of-requests-per-day/
  • 11. Why offer an API? •  Avoid (control) scraping •  Develop partnerships – “Business development 2.0” •  New distribution channels •  Increase revenue (if paid) •  Externalize innovation – Copy the best? •  Customer lock-in through integration From Code to Product Lecture 9 — Web API Design — Slide 11 gidgreen.com/course
  • 12. Business questions •  What is our goal for the API? – How does it contribute to business? •  Free vs paid? – Revenue generation vs marketing •  Who will use it? – Aim at those developers’ success •  What do they want to do with it? – Can our competitors make use of it? From Code to Product Lecture 9 — Web API Design — Slide 12 gidgreen.com/course
  • 13. API-focused companies: Stripe From Code to Product Lecture 9 — Web API Design — Slide 13 gidgreen.com/course
  • 14. API-focused companies: Zencoder From Code to Product Lecture 9 — Web API Design — Slide 14 gidgreen.com/course
  • 15. API-only companies: SendGrid From Code to Product Lecture 9 — Web API Design — Slide 15 gidgreen.com/course
  • 16. API-only companies: Twilio From Code to Product Lecture 9 — Web API Design — Slide 16 gidgreen.com/course
  • 17. API vs licensing code •  Better business model – Recurring revenue (by usage) – Suits small and large clients •  Easier to maintain – No need for “releases” – Controlled environment •  Keep control over IP •  But it’s a serious operation – Risk of downtime (SLAs?) From Code to Product Lecture 9 — Web API Design — Slide 17 gidgreen.com/course
  • 18. Lecture 9 •  Introduction •  REST •  Data formats •  Security •  Maintenance •  Documentation •  Resources From Code to Product Lecture 9 — Web API Design — Slide 18 gidgreen.com/course
  • 19. REST •  Representational State Transfer – Most popular design model for Web APIs •  Entities (“resources”) = URLs •  Actions = HTTP commands – GET, POST, PUT, DELETE •  Resources are self-descriptive •  No hidden server-side state •  (UI Principles applied to developers!) From Code to Product Lecture 9 — Web API Design — Slide 19 gidgreen.com/course
  • 20. HTTP request example PUT /api/dogs/3 HTTP/1.1 Host: dog-db.com Content-Type: application/x-www-form-urlencoded Content-Length: 21 Request data... From Code to Product Lecture 9 — Web API Design — Slide 20 gidgreen.com/course HTTP/1.1 200 OK Content-Type: application/json;charset=utf-8 Content-Length: 94 Response data…
  • 21. REST GET Example 1 GET http://dog-db.com/api/dogs [ { id:1, name:"Fido" }, { id:2, name:"Rover" }, { id:3, name:"Spot" }, { id:4, name:"Fluffy" }, ] From Code to Product Lecture 9 — Web API Design — Slide 21 gidgreen.com/course
  • 22. REST GET Example 2 GET http://dog-db.com/api/dogs/3 { id:3, name:"Spot", dob:"2009-05-21", type:"spaniel", photo:"http://dog-db/images/… From Code to Product Lecture 9 — Web API Design — Slide 22 gidgreen.com/course
  • 24. HTTP command Database operation /dogs /dogs/3 GET Read List all dogs Get dog details POST Create Create new dog — PUT Update — Update detail/s DELETE Delete Delete all dogs Delete this dog REST as CRUD From Code to Product Lecture 9 — Web API Design — Slide 24 gidgreen.com/course
  • 25. REST PUT Example PUT http://dog-db/api/dogs/3 name=Fifi&type=poodle { id:3, name:”Fifi", dob:"2009-05-21", type:”poodle”, From Code to Product Lecture 9 — Web API Design — Slide 25 gidgreen.com/course
  • 26. Rules for REST actions •  GET does not change server state – Allows caching, prefetching – Like requesting web page •  PUT and DELETE are “idempotent” – Repeated calls don’t matter •  POST can change server state each time – Classic example: transfer money – Like submitting web form From Code to Product Lecture 9 — Web API Design — Slide 26 gidgreen.com/course
  • 27. Choosing REST URLs •  Stick to plural forms – /dogs → /dogs/3 not /dog/3 •  Avoid abstractions – /dogs/3 better than /entities/3 •  If multiple return types: – /dogs/3?type=json – /dogs/3.json •  Consistency is king! From Code to Product Lecture 9 — Web API Design — Slide 27 gidgreen.com/course
  • 28. More URL best practices •  Pagination of results – ?start=20&count=10 •  Subset of fields – ?fields=id,name,owner,type •  API calls not on resources – GET /api/search?q=... – GET /api/convert? from=km&to=inch&value=0.63 From Code to Product Lecture 9 — Web API Design — Slide 28 gidgreen.com/course
  • 29. Other protocols •  Simple Object Access Protocol (SOAP) – XML-based + lots of extra cruft – Hard to read and write manually – Formalization and discovery via WSDL •  XML-Remote Procedure Call (XML-RPC) – Simpler precursor to SOAP – Based on functions, e.g. getDogName() •  Neither uses URLs for entities From Code to Product Lecture 9 — Web API Design — Slide 29 gidgreen.com/course
  • 30. Lecture 9 •  Introduction •  REST •  Data formats •  Security •  Maintenance •  Documentation •  Resources From Code to Product Lecture 9 — Web API Design — Slide 30 gidgreen.com/course
  • 31. Important data types •  String •  Number •  Boolean •  Date/time •  Null/nil •  Binary large objects (BLOBs) •  Array = unlabeled ordered list •  Object = labeled (ordered) list From Code to Product Lecture 9 — Web API Design — Slide 31 gidgreen.com/course Scalars
  • 32. Extensible Markup Language (XML) <dogs> <dog id="3"> <name>Spot</name> <age>7</age> <type></type> <owner id="16"> <name>Sam</name> </owner> <collar>true</collar> </dog> <dog id="4"> ... From Code to Product Lecture 9 — Web API Design — Slide 32 gidgreen.com/course ü  User friendly ü  Looks like HTML ⨯ Wordy ⨯ Elements vs attributes ⨯ Implicit typing ⨯ "123" ⨯ Array of one
  • 33. RSS 2.0 (see also: Atom) <rss version="2.0"> <channel> <title>Dog Tales</title> <description>Stories about dogs</description> <link>http://dog-tales.com/</link> <item> <title>Cat chasing</title> <description>A dog ran after a cat</description> <link>http://dog-tales.com/</link> <pubDate>Thu, 09 May 2013 16:45:00 +0000</pubDate> </item> <item> ... From Code to Product Lecture 9 — Web API Design — Slide 33 gidgreen.com/course
  • 34. Javascript Object Notation (JSON) [ { id:3, name:"Spot", age:7, type:null, owner:{id:16,name:"Sam"}, collar:true, }, { id:4, ... From Code to Product Lecture 9 — Web API Design — Slide 34 gidgreen.com/course ü  Compact ü  Explicit types ü  [] vs {} ü  Javascript-ish ü  JSONP for web access ⨯ Feels like programming
  • 35. Urlencoding •  URL parameters •  Multifield forms (PUT/POST) From Code to Product Lecture 9 — Web API Design — Slide 35 gidgreen.com/course http://dog-tales.com/
  • 36. BLOBs (rich media) •  Raw delivery – Can’t be combined with other data – For HTTP use MIME to identify •  Provide URL (string) – Separate request to retrieve •  Base64 encoding – Inflates size by 33% – Standard method for web forms From Code to Product Lecture 9 — Web API Design — Slide 36 gidgreen.com/course
  • 37. Error reporting •  Use HTTP response code – Allow suppression, e.g. for Flash •  Error in response: { http-code:401, error-code:-329, error-message:"Invalid API key", error-help:"http://dog-db.com/docs errors/-329.html” From Code to Product Lecture 9 — Web API Design — Slide 37 gidgreen.com/course
  • 38. HTTP response codes From Code to Product Lecture 9 — Web API Design — Slide 38 gidgreen.com/course HTTP code Meaning 200 OK 4xx Bad request (client’s fault) 5xx Failed request (server’s fault) 401 Unauthorized request 404 Resource not found 500 Internal error (bug) 503 Server overloaded
  • 39. Lecture 9 •  Introduction •  REST •  Data formats •  Security •  Maintenance •  Documentation •  Resources From Code to Product Lecture 9 — Web API Design — Slide 39 gidgreen.com/course
  • 40. Simple HTTP Authentication GET /api/dogs/?appID=29838&key=k234nb3bf89 Host: dog-db.com GET /api/dogs/ Host: dog-db.com Authorization: Basic QWxhZGRpbjpvcGc2FtZQ== From Code to Product Lecture 9 — Web API Design — Slide 40 gidgreen.com/course ü  Trivial for developers ⨯ Visible to intermediaries ü  https can solve this
  • 41. Signing API calls •  Client and server share secret key •  Signature is hash (one-way function) of: – Request – Parameters (alphabetical order) – Secret key •  Best practice: multiple keys per user – Users can disable some applications •  Problem: replay attacks From Code to Product Lecture 9 — Web API Design — Slide 41 gidgreen.com/course
  • 42. OAuth 1.0 •  Standard for digitally signing API calls •  Permits delegation – User grants temporary access to API for them •  Prevents replay attacks – Via ‘nonce’ = number used once •  Popular industry standard – Dropbox, Evernote, Flickr, Twitter •  See also: OAuth 2.0 From Code to Product Lecture 9 — Web API Design — Slide 42 gidgreen.com/course
  • 43. Rate limiting •  Per IP address, but… – Proxy networks e.g. Tor – Temporary cloud instances •  Per API key, but… – Multiple key signups •  Per queried entity •  Based on (API) server load •  Charging solves everything… From Code to Product Lecture 9 — Web API Design — Slide 43 gidgreen.com/course
  • 44. Final comments on security •  Do not trust clients – All input must be sanitized •  Clients must store key – So desktop/mobile apps hackable •  You can’t take back data – Limit scope of responses •  Don’t reinvent the wheel – Save developers time From Code to Product Lecture 9 — Web API Design — Slide 44 gidgreen.com/course
  • 45. Lecture 9 •  Introduction •  REST •  Data formats •  Security •  Maintenance •  Documentation •  Resources From Code to Product Lecture 9 — Web API Design — Slide 45 gidgreen.com/course
  • 46. Maintenance issues •  Downtime •  Versioning •  Scaling •  Monitoring •  Logging From Code to Product Lecture 9 — Web API Design — Slide 46 gidgreen.com/course
  • 47. Downtime •  Developers test then deploy – When you go down, they go down •  So avoid at all costs by: – Monitoring – Versioning •  If unavoidable then: – Do it on the weekend – Give advanced notice From Code to Product Lecture 9 — Web API Design — Slide 47 gidgreen.com/course
  • 48. API status From Code to Product Lecture 9 — Web API Design — Slide 48 gidgreen.com/course
  • 49. Versioning GET http://dog-db.com/api/v1/dogs/ •  Version at start of URL •  v1 then v2 — no v1.1 – Makes compatibility clear •  Maintain one version back •  It’s still a failure – Add URLs/parameters instead From Code to Product Lecture 9 — Web API Design — Slide 49 gidgreen.com/course
  • 50. Scaling •  Usage volumes can surprise you – You’re serving software, not people – Small number of heavy users – Very peaky traffic •  Caching is your friend •  Drop expensive requests under load •  Slow response better than none •  Separate domain: api.dog-db.com From Code to Product Lecture 9 — Web API Design — Slide 50 gidgreen.com/course
  • 51. Monitoring •  Volume of API calls •  Popular calls •  Response time •  Error rates •  Active developers – Hyperactive developers •  Revenue (+indirect) vs costs From Code to Product Lecture 9 — Web API Design — Slide 51 gidgreen.com/course
  • 52. Monitoring made public From Code to Product Lecture 9 — Web API Design — Slide 52 gidgreen.com/course
  • 53. Logging •  Log everything – Incoming requests – Outgoing response – Response time •  To enable… – Bug resolution – Abuse forensics – Deeper (offline) analytics From Code to Product Lecture 9 — Web API Design — Slide 53 gidgreen.com/course
  • 54. Lecture 9 •  Introduction •  REST •  Data formats •  Security •  Maintenance •  Documentation •  Conclusion From Code to Product Lecture 9 — Web API Design — Slide 54 gidgreen.com/course
  • 55. Documentation •  Reference •  Examples •  API explorer •  Language libraries •  Example apps •  Discussion forum •  (and support) From Code to Product Lecture 9 — Web API Design — Slide 55 gidgreen.com/course
  • 56. Reference: security From Code to Product Lecture 9 — Web API Design — Slide 56 gidgreen.com/course
  • 57. Reference: URLs From Code to Product Lecture 9 — Web API Design — Slide 57 gidgreen.com/course
  • 58. Reference: input parameters From Code to Product Lecture 9 — Web API Design — Slide 58 gidgreen.com/course
  • 59. For each input parameter •  Name of parameter •  Explanation/meaning •  Possible values/range •  Example values •  Optional or required? – Default value if optional From Code to Product Lecture 9 — Web API Design — Slide 59 gidgreen.com/course
  • 60. Reference: output fields From Code to Product Lecture 9 — Web API Design — Slide 60 gidgreen.com/course
  • 61. Reference: response codes From Code to Product Lecture 9 — Web API Design — Slide 61 gidgreen.com/course
  • 62. Examples From Code to Product Lecture 9 — Web API Design — Slide 62 gidgreen.com/course
  • 63. API explorer From Code to Product Lecture 9 — Web API Design — Slide 63 gidgreen.com/course
  • 64. Language libraries From Code to Product Lecture 9 — Web API Design — Slide 64 gidgreen.com/course ü  Developers save time ü  Get fewer bad API calls ⨯ You must learn many languages ⨯ Maintenance
  • 65. Example apps From Code to Product Lecture 9 — Web API Design — Slide 65 gidgreen.com/course
  • 66. Discussion forum From Code to Product Lecture 9 — Web API Design — Slide 66 gidgreen.com/course
  • 67. Lecture 9 •  Introduction •  REST •  Data formats •  Security •  Maintenance •  Documentation •  Conclusion From Code to Product Lecture 9 — Web API Design — Slide 67 gidgreen.com/course
  • 68. Things to avoid •  Lengthy signup process •  Exposing raw/ugly data •  Complex security model •  Breaking backwards compatibility •  Inaccurate documentation •  Multi-call operations (“chatty APIs”) •  Developer frustration From Code to Product Lecture 9 — Web API Design — Slide 68 gidgreen.com/course
  • 69. Books From Code to Product Lecture 9 — Web API Design — Slide 69 gidgreen.com/course
  • 70. Resources and services From Code to Product Lecture 9 — Web API Design — Slide 70 gidgreen.com/course