Top Banner
Advanced API Design How an awesome API can attract friends, make you rich, and change the world Jon Dahl @jondahl [email protected]
119

Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Nov 07, 2014

Download

Technology

Jonathan Dahl

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Advanced API DesignHow an awesome API can

attract friends, make you rich,

and change the world

Jon Dahl@jondahl

[email protected]

Page 2: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 3: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

ApplicationProgrammingInterface

Page 4: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

UserInterface

Page 5: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Interface

Page 6: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

LibrarySDK

Page 7: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Net::SSH

Page 8: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Web Service

Page 9: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

SimpleObjectAccessProtocol

Page 10: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

SimpleObjectAccessProtocol

Page 11: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

REST

Page 12: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP

Page 13: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Web is an API

Page 14: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET /records

Page 15: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

POST /record/new

Page 16: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

POST /record/new<xml> <data>Foo</data></xml>

Page 17: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

POST /record/new{ "data" : "foo"}

Page 18: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 19: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

(Don’t tell our investors that we don’t have a real product)

Page 20: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 21: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Some Examples

Page 22: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

1. Second InterfaceFlickrTwitterLinkedinFacebookPaypalGoogle Maps

Page 23: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

2. Internal APIsService Oriented ArchitectureMobile application backends

Page 24: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

3. Core TechAmazon Web ServicesTwilioGeoloqiZencoderSendgrid FactualSpreedlyRecurlySaploTropoCloudMailinUploadJuicer

Page 25: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

4. Science FictionPiCloudAmazon Mechanical Turk...

Page 26: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

so, how do you design a good API?

Page 27: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 28: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 29: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 30: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Competitive Advantage

Page 31: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

REST conventions

Page 32: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET POSTPUTDELETE

recordsjobsmessagesserversusers

Page 33: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP codes

Page 34: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

200 OK201 Created202 Accepted

400 Bad Request401 Unauthorized402 Payment Required404 Not Found409 Conflict418 I’m a teapot422 Unprocessable Entity

500 Internal Server Error503 Service Unavailable

Page 35: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

... and many more!

Page 36: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Version it

Page 37: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET /api/records/38927

{ "color" : "green", "velocity" : 1000000}

Page 38: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET /api/records/38927

{ "color" : "10EE33", "velocity" : 1000000}

Page 39: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET /api/v1/records/38927

{ "color" : "green", "velocity" : 1000000}

Page 40: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET /api/v2/records/38927

{ "color" : "10EE33", "velocity" : 1000000}

Page 41: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET /api/records/38927?version=2

GET /api/v2/records/38927

GET /api/records/38927Accept: application/json+v2

Page 42: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Smart validations

Page 43: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

POST /api/jobs HTTP/1.1Accept: application/jsonContent-Type: application/json

{ "api_key" : "Not A Real Key", "color" : "green"}

Page 44: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP/1.1 500 Internal Server Error

Page 45: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP/1.1 401 Unauthorized

Page 46: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP/1.1 401 Unauthorized

{ "errors": [ "api_key not found" ]}

Page 47: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP/1.1 401 Unauthorized

{ "errors": [ "api_key not found.", "api_key may not include spaces." ]}

Page 48: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP/1.1 401 Unauthorized

{ "errors": [ "api_key not found. Please log in to https://example.com/account/api to retrieve your API key.", "api_key may not include spaces." ]}

Page 49: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

POST /api/user HTTP/1.1Accept: application/jsonContent-Type: application/json

{ "api_key" : "A23B92F281CC" "strength" : 18}

Page 50: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP/1.1 400 Bad Request

Page 51: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

HTTP/1.1 400 Bad Request

{ "errors": [ "JSON is not valid. Syntax error, unexpected TSTRING, expecting '}' at line 2" ]}

Page 52: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

JSON + XML

Page 53: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 54: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 55: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

POST /api/user HTTP/1.1Accept: application/jsonContent-Type: application/json

{ "api_key" : "A23B92F281CC", "strength" : 18}

Page 56: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

params[:strength] # 18

Page 57: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

respond_to do |wants| wants.json { render :json => @jobs.to_json } wants.xml { render :xml => @jobs.to_xml } end

Page 58: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Document it

Page 59: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Zencoder::API.define_setting :audio_channels, :section => section do |z| z.tip = "The number of audio channels: 1 or 2." z.description = %Q{ <p>The number of audio channels to use: 1 (mono) or 2 (stereo).</p> <p>Note that mono AAC audio sometimes erroneously self-reports as stereo when inspected. We recommend using iTunes to get the true number of channels for AAC audio.</p> } z.data_type = "Integer" z.valid = "1 or 2" z.default = "1 if the original file is mono; otherwise, 2." z.example = "1" z.see_also = [:audio_bitrate, :audio_quality]end

Page 60: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 61: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Libraries

Page 62: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Support it

Page 63: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

APIs are scary.

Page 64: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Make it fast

Page 65: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Rate limiting

Page 66: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

loop { MyApi.create("data") }

Page 67: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Log requests

Page 68: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 69: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 70: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Request builder

Page 71: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 72: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 73: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

GET /api/ideas

Page 74: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Competitive Advantage

Page 75: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

1. Make friends

Page 76: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 77: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Awesomeness is noticed

Page 78: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

(Assymetrical value curve)

Page 79: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

value

quality

Page 80: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

value

quality

Page 81: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

value

quality

Page 82: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Bus Driving

quality

value

Page 83: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Bus Drivingvalue

quality

Page 84: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 85: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Sportsvalue

quality

Page 86: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

API designvalue

quality

Page 87: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

"I know the following statement is going to sound dramatic, but it's the truth. Zencoder seriously uplifted my entire day.

The API is really well designed and has documentation for not only what each value should be but also what an example input/output would look like using the value. I had spent the earlier part of the day working with a web service that is the complete opposite of those things.

So when I started digging into Zencoder I felt like I was witnessing a double rainbow. Then when I found the API Builder, it went beyond a double rainbow to a level I can only imagine is equal to witnessing a unicorn birth.”

Page 88: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

2. Get rich

Page 89: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Software is eating the world

Page 90: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Software is eating the world

Page 91: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

$0B

$50B

$100B

$150B

2010 2014

$148.8B

$68.3B

Cloud computing revenue forecast

Source: Gartner 2010

Page 92: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Need an idea?

Page 93: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

API to

Page 94: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

API to the government

Page 95: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

API to your body

Page 96: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

API to manufacturing

Page 97: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

3. Change the world

Page 98: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 99: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 100: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

In 2000...the cost of a customer running a basic Internet application was approximately $150,000 a month. Running that same application today in Amazon's cloud costs about $1,500 a month.

Mark Andreessen, “Why Software Is Eating The World”

Page 101: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 102: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 103: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 104: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 105: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 106: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 107: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 108: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 109: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 110: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

1,000 CPU cores:

Page 111: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

1,000 CPU cores:$204

Page 112: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

50 phone numbers:

Page 113: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

50 phone numbers:$50

Page 114: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

POST /api/awesome_things HTTP/1.1

{ "team_size" : 3, "productivity" : "10x"}

Page 115: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 116: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 117: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 118: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world
Page 119: Advanced API Design: how an awesome API can help you make friends, get rich, and change the world

Jon Dahl@jondahl

[email protected]