103
Advanced API Design How an awesome API can attract friends, make you rich, and change the world Jon Dahl @jondahl [email protected] Monday, May 23, 2011

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

Embed Size (px)

Citation preview

Advanced API DesignHow an awesome API can

attract friends, make you rich,

and change the world

Jon Dahl@jondahl

[email protected]

Monday, May 23, 2011

ApplicationProgrammingInterface

Monday, May 23, 2011

UserInterface

Monday, May 23, 2011

Interface

Monday, May 23, 2011

LibrarySDK

Monday, May 23, 2011

Net::SSH

Monday, May 23, 2011

Web Service

Monday, May 23, 2011

SimpleObjectAccessProtocol

Monday, May 23, 2011

SimpleObjectAccessProtocol

Monday, May 23, 2011

REST

Monday, May 23, 2011

HTTP

Monday, May 23, 2011

Web is an API

Monday, May 23, 2011

GET /records

Monday, May 23, 2011

POST /record/new

Monday, May 23, 2011

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

Monday, May 23, 2011

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

Monday, May 23, 2011

Monday, May 23, 2011

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

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

1. SecondaryFlickrTwitterLinkedinFacebook

Monday, May 23, 2011

2. InfrastructureAmazon Web Services

EC2S3SQSRDSSNSSES

Monday, May 23, 2011

3. TechnologyTwilioSimpleGeoSendgridZencoderFactualSpreedlyRecurlySaploTropoCloudMailinUploadJuicer

Monday, May 23, 2011

4. Science FictionPiCloudCrowdflowerAmazon Mechanical Turk

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

so, how do you design a good API?

Monday, May 23, 2011

Version it

Monday, May 23, 2011

GET /api/records/38927

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

Monday, May 23, 2011

GET /api/records/38927

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

Monday, May 23, 2011

GET /api/v1/records/38927

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

Monday, May 23, 2011

GET /api/v2/records/38927

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

Monday, May 23, 2011

REST conventions

Monday, May 23, 2011

GET POSTPUTDELETE

recordsjobsmessagesserversusers

Monday, May 23, 2011

HTTP codes

Monday, May 23, 2011

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

Monday, May 23, 2011

... and many more!

Monday, May 23, 2011

Smart validations

Monday, May 23, 2011

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

{ "api_key" : "Not A Real Key"}

Monday, May 23, 2011

HTTP/1.1 500 Internal Server Error

Monday, May 23, 2011

HTTP/1.1 401 Unauthorized

Monday, May 23, 2011

HTTP/1.1 401 Unauthorized

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

Monday, May 23, 2011

HTTP/1.1 401 Unauthorized

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

Monday, May 23, 2011

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." ]}

Monday, May 23, 2011

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

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

Monday, May 23, 2011

HTTP/1.1 400 Bad Request

Monday, May 23, 2011

HTTP/1.1 400 Bad Request

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

Monday, May 23, 2011

JSON + XML

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

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

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

Monday, May 23, 2011

params[:strength] # 18

Monday, May 23, 2011

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

Monday, May 23, 2011

Document it

Monday, May 23, 2011

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

Monday, May 23, 2011

Monday, May 23, 2011

Libraries

Monday, May 23, 2011

Support it

Monday, May 23, 2011

APIs are scary.

Monday, May 23, 2011

Make it fast

Monday, May 23, 2011

Rate limiting

Monday, May 23, 2011

Log requests

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Request builder

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

GET /api/ideas

Monday, May 23, 2011

1. Make friends

Monday, May 23, 2011

Monday, May 23, 2011

Awesomeness is noticed

Monday, May 23, 2011

(Assymetrical reward curve)

Monday, May 23, 2011

value

quality

Monday, May 23, 2011

value

quality

Monday, May 23, 2011

value

quality

Monday, May 23, 2011

Bus Driving

quality

value

Monday, May 23, 2011

Bus Drivingvalue

quality

Monday, May 23, 2011

Monday, May 23, 2011

Sportsvalue

quality

Monday, May 23, 2011

API designvalue

quality

Monday, May 23, 2011

"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.”

Monday, May 23, 2011

2. Get rich

Monday, May 23, 2011

$0B

$50B

$100B

$150B

2010 2014

$148.8B

$68.3B

Cloud computing revenue forecast

Source: Gartner 2010

Monday, May 23, 2011

4.TwilioSimpleGeoSendgridZencoderFactualSpreedlyRecurlySaploTropoCloudMailinUploadJuicer

Monday, May 23, 2011

API to

Monday, May 23, 2011

API to Ruby

Monday, May 23, 2011

API to the government

Monday, May 23, 2011

API to manufacturing

Monday, May 23, 2011

3. Change the world

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

Monday, May 23, 2011

POST /api/awesome_things HTTP/1.1

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

Monday, May 23, 2011

Jon Dahl@jondahl

[email protected]

Thanks!

Monday, May 23, 2011