Slide 1

Slide 1 text

WYNN NETHERLAND User Experience Patterns for APIs

Slide 2

Slide 2 text

Howdy!

Slide 3

Slide 3 text

Wynn Netherland My name is

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

.com

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

I write API wrappers

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

UX Patterns for APIs and anti-patterns ^

Slide 14

Slide 14 text

Support curling PATTERN

Slide 15

Slide 15 text

curl -i https://api.github.com/users/defunkt HTTP/1.1 200 OK Server: nginx Date: Wed, 12 Sep 2012 14:07:43 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Status: 200 OK Content-Length: 692 X-Content-Type-Options: nosniff X-RateLimit-Remaining: 4997 X-RateLimit-Limit: 5000 Cache-Control: public, s-maxage=60, max-age=60 Vary: Accept X-GitHub-Media-Type: github.beta ETag: "ef742caec0c19e2169ffb05e7d200d17" Last-Modified: Tue, 11 Sep 2012 02:52:21 GMT { "following": 212, "type": "User", "html_url": "https://github.com/defunkt", "location": "San Francisco", "hireable": true,

Slide 16

Slide 16 text

curl -i -u pengwynn \ https://api.github.com/user

Slide 17

Slide 17 text

curl -i -u pengwynn \ https://api.github.com/user include response headers

Slide 18

Slide 18 text

curl -i -u pengwynn \ https://api.github.com/user use Basic Auth, prompt for password

Slide 19

Slide 19 text

Security mazes ANTI-PATTERN

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

OAuth is painful. OAuth2 hurts less.

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Insane URLs ANTI-PATTERN

Slide 24

Slide 24 text

http://sandbox.api.shopping.com/publisher/ 3.0/rest/GeneralSearch? hybridSortType=relevance&productSortType=r elevance&offerSortType=store- name&productReviewSortType=review-date

Slide 25

Slide 25 text

http://maps.googleapis.com/maps/api/ staticmap?center=Brooklyn+Bridge,New +York,NY&zoom=13&size=600x300&maptype=road map&markers=color:blue%7Clabel:S %7C40.702147,-74.015794&markers=color:gree n%7Clabel:G%7C40.711614,-74.012318 &markers=color:red%7Ccolor:red%7Clabel:C %7C40.718217,-73.998284&sensor=false

Slide 26

Slide 26 text

Maximize the payload PATTERN

Slide 27

Slide 27 text

{ "uri": "/pengwynn/githubbers", "name": "GitHubbers", "full_name": "@pengwynn/githubbers", "description": "", "mode": "public", "user": { "id": 14100886, "favourites_count": 275, "profile_image_url": "http://a0.twimg.com/profile_ima...", "profile_background_tile": false, "profile_sidebar_fill_color": "DDEEF6", "verified": false, "location": "Denton, TX", "utc_offset": -21600, "name": "Wynn Netherland", "lang": "en", "is_translator": false, "default_profile": true, "profile_background_color": "C0DEED", "protected": false, "contributors_enabled": false, "time_zone": "Central Time (US & Canada)", "profile_background_image_url": "http://a0.twimg.com/images/themes/...", "profile_link_color": "0084B4", "description": "Christian, husband, father, GitHubber, Co-host...", "geo_enabled": true, "listed_count": 388, "show_all_inline_media": true, "notifications": false, "id_str": "14100886", "statuses_count": 7178, "profile_image_url_https": "https://si0.twimg.com/profile_images/2221455972/

Slide 28

Slide 28 text

{ "uri": "/pengwynn/githubbers", "name": "GitHubbers", "full_name": "@pengwynn/githubbers", "description": "", "mode": "public", "user": { "id": 14100886, "favourites_count": 275, "profile_image_url": "http://a0.twimg.com/profile_ima...", "profile_background_tile": false, "profile_sidebar_fill_color": "DDEEF6", "verified": false, "location": "Denton, TX", "utc_offset": -21600, "name": "Wynn Netherland", "lang": "en", "is_translator": false, "default_profile": true, "profile_background_color": "C0DEED", "protected": false, "contributors_enabled": false, "time_zone": "Central Time (US & Canada)", "profile_background_image_url": "http://a0.twimg.com/images/themes/...", "profile_link_color": "0084B4", "description": "Christian, husband, father, GitHubber, Co-host...", "geo_enabled": true, "listed_count": 388, "show_all_inline_media": true, "notifications": false, "id_str": "14100886", "statuses_count": 7178, "profile_image_url_https": "https://si0.twimg.com/profile_images/2221455972/ Full User object

Slide 29

Slide 29 text

Rock the cache PATTERN

Slide 30

Slide 30 text

curl -I https://api.github.com/users/defunkt HTTP/1.1 200 OK Server: nginx Date: Wed, 12 Sep 2012 14:07:43 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Status: 200 OK Content-Length: 692 X-Content-Type-Options: nosniff X-RateLimit-Remaining: 4997 X-RateLimit-Limit: 5000 Cache-Control: public, s-maxage=60, max-age=60 Vary: Accept X-GitHub-Media-Type: github.beta ETag: "ef742caec0c19e2169ffb05e7d200d17" Last-Modified: Tue, 11 Sep 2012 02:52:21 GMT

Slide 31

Slide 31 text

curl -I https://api.github.com/users/defunkt HTTP/1.1 200 OK Server: nginx Date: Wed, 12 Sep 2012 14:07:43 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Status: 200 OK Content-Length: 692 X-Content-Type-Options: nosniff X-RateLimit-Remaining: 4997 X-RateLimit-Limit: 5000 Cache-Control: public, s-maxage=60, max-age=60 Vary: Accept X-GitHub-Media-Type: github.beta ETag: "ef742caec0c19e2169ffb05e7d200d17" Last-Modified: Tue, 11 Sep 2012 02:52:21 GMT

Slide 32

Slide 32 text

curl -I https://api.github.com/users/defunkt HTTP/1.1 200 OK Server: nginx Date: Wed, 12 Sep 2012 14:07:43 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Status: 200 OK Content-Length: 692 X-Content-Type-Options: nosniff X-RateLimit-Remaining: 4997 X-RateLimit-Limit: 5000 Cache-Control: public, s-maxage=60, max-age=60 Vary: Accept X-GitHub-Media-Type: github.beta ETag: "ef742caec0c19e2169ffb05e7d200d17" Last-Modified: Tue, 11 Sep 2012 02:52:21 GMT Cache policy

Slide 33

Slide 33 text

curl -I https://api.github.com/users/defunkt HTTP/1.1 200 OK Server: nginx Date: Wed, 12 Sep 2012 14:07:43 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Status: 200 OK Content-Length: 692 X-Content-Type-Options: nosniff X-RateLimit-Remaining: 4997 X-RateLimit-Limit: 5000 Cache-Control: public, s-maxage=60, max-age=60 Vary: Accept X-GitHub-Media-Type: github.beta ETag: "ef742caec0c19e2169ffb05e7d200d17" Last-Modified: Tue, 11 Sep 2012 02:52:21 GMT Fingerprint

Slide 34

Slide 34 text

curl -I \ -H 'If-None-Match:"ef742caec0c19e2169ffb05e7d200d17" \ https://api.github.com/users/defunkt HTTP/1.1 304 Not Modified Server: nginx Date: Wed, 12 Sep 2012 15:51:39 GMT Connection: keep-alive Status: 304 Not Modified X-RateLimit-Limit: 5000 X-Content-Type-Options: nosniff Vary: Accept ETag: "ef742caec0c19e2169ffb05e7d200d17" X-RateLimit-Remaining: 4997 Last-Modified: Wed, 12 Sep 2012 01:38:14 GMT Cache-Control: public, s-maxage=60, max-age=60

Slide 35

Slide 35 text

curl -H 'If-None-Match:"ef742caec0c19e2169ffb05e7d200d17" \ https://api.github.com/users/defunkt HTTP/1.1 304 Not Modified Server: nginx Date: Wed, 12 Sep 2012 15:51:39 GMT Connection: keep-alive Status: 304 Not Modified X-RateLimit-Limit: 5000 X-Content-Type-Options: nosniff Vary: Accept ETag: "ef742caec0c19e2169ffb05e7d200d17" X-RateLimit-Remaining: 4997 Last-Modified: Wed, 12 Sep 2012 01:38:14 GMT Cache-Control: public, s-maxage=60, max-age=60

Slide 36

Slide 36 text

$ curl -i https://api.github.com/user HTTP/1.1 200 OK Cache-Control: private, max-age=60 ETag: "644b5b0155e6404a9cc4bd9d8b1ae730" Last-Modified: Thu, 05 Jul 2012 15:31:30 GMT Status: 200 OK Vary: Accept, Authorization, Cookie X-RateLimit-Limit: 5000 X-RateLimit-Remaining: 4996 $ curl -i https://api.github.com/user -H "If-Modified-Since: Thu, 05 Jul 2012 15:31:30 GMT" HTTP/1.1 304 Not Modified Cache-Control: private, max-age=60 Last-Modified: Thu, 05 Jul 2012 15:31:30 GMT Status: 304 Not Modified Vary: Accept, Authorization, Cookie X-RateLimit-Limit: 5000 X-RateLimit-Remaining: 4996 $ curl -i https://api.github.com/user -H 'If-None-Match: "644b5b0155e6404a9cc4bd9d8b1ae730"' HTTP/1.1 304 Not Modified Cache-Control: private, max-age=60 ETag: "644b5b0155e6404a9cc4bd9d8b1ae730" Last-Modified: Thu, 05 Jul 2012 15:31:30 GMT Status: 304 Not Modified Vary: Accept, Authorization, Cookie X-RateLimit-Limit: 5000 X-RateLimit-Remaining: 4996

Slide 37

Slide 37 text

Dogfood it PATTERN

Slide 38

Slide 38 text

Build something meaningful with your API.

Slide 39

Slide 39 text

Build something meaningful with your API. Janky

Slide 40

Slide 40 text

Build something meaningful with your API. Janky Heaven

Slide 41

Slide 41 text

Build something meaningful with your API. Janky Heaven Monitors

Slide 42

Slide 42 text

Build something meaningful with your API. Janky Team Heaven Monitors

Slide 43

Slide 43 text

Build something meaningful with your API. Janky Team Hire Heaven Monitors

Slide 44

Slide 44 text

Build something meaningful with your API. Janky Team Hire Heaven Monitors The Setup™

Slide 45

Slide 45 text

Build something meaningful with your API. Janky Team Hire Heaven Monitors The Setup™ Graph Store

Slide 46

Slide 46 text

How GitHub uses the GitHub API.

Slide 47

Slide 47 text

How GitHub uses the GitHub API. AuthN

Slide 48

Slide 48 text

How GitHub uses the GitHub API. AuthN AuthZ

Slide 49

Slide 49 text

How GitHub uses the GitHub API. AuthN AuthZ Merging

Slide 50

Slide 50 text

How GitHub uses the GitHub API. AuthN AuthZ Merging Commit Status

Slide 51

Slide 51 text

How GitHub uses the GitHub API. AuthN AuthZ Merging Commit Status GFM

Slide 52

Slide 52 text

Oh, and native apps.

Slide 53

Slide 53 text

Oh, and native apps. GitHub for Mac

Slide 54

Slide 54 text

Oh, and native apps. GitHub for Mac GitHub for Windows

Slide 55

Slide 55 text

PATTERN Use HTTP status codes

Slide 56

Slide 56 text

HTTP/1.1 200 OK Server: nginx Date: Wed, 12 Sep 2012 14:07:43 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Status: 200 OK ETag: "ef742caec0c19e2169ffb05e7d200d17" Last-Modified: Tue, 11 Sep 2012 02:52:21 GMT { "error_code": 1234, "error": "User not found" }

Slide 57

Slide 57 text

HTTP/1.1 404 Not Found Server: nginx Date: Wed, 12 Sep 2012 14:07:43 GMT Content-Type: application/json; charset=utf-8 Connection: keep-alive Status: 404 Not Found

Slide 58

Slide 58 text

Confusing header with body ANTI-PATTERN

Slide 59

Slide 59 text

Harsh rate limits ANTI-PATTERN

Slide 60

Slide 60 text

$ curl -i https://api.github.com/users/ whatever? client_id=xxxxxxxxxxxxxx&client_secret=yyy yyyyyyyyyyyyyyyyyy HTTP/1.1 200 OK Status: 200 OK X-RateLimit-Limit: 12500 X-RateLimit-Remaining: 11966

Slide 61

Slide 61 text

Announce breaking changes PATTERN

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Make documentation obvious PATTERN

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

Create awesome guides PATTERN

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Consoles PATTERN

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

ANTI-PATTERN Endless terms of service changes

Slide 76

Slide 76 text

Inconsistency ANTI-PATTERN

Slide 77

Slide 77 text

POST /gists/:id/fork POST /repos/:user/:repo/merges

Slide 78

Slide 78 text

Fast, transparent support PATTERN

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

Free samples PATTERN

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

Mashup friendly PATTERN

Slide 83

Slide 83 text

JSONP

Slide 84

Slide 84 text

$ curl https://api.github.com?callback=foo foo({ "meta": { "status": 200, "X-RateLimit-Limit": "5000", "X-RateLimit-Remaining": "4966", "Link": [ // pagination headers and other links ["https://api.github.com?page=2", {"rel": "next"}] ] }, "data": { // the data } })

Slide 85

Slide 85 text

CORS

Slide 86

Slide 86 text

$ curl -i https://api.github.com \ -H "Origin: http://calendaraboutnothing.com" HTTP/1.1 302 Found Access-Control-Allow-Origin: http://calendaraboutnothing.com Access-Control-Expose-Headers: Link, X-RateLimit-Limit, X- RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes Access-Control-Allow-Credentials: true

Slide 87

Slide 87 text

$ curl -i https://api.github.com \ -H "Origin: http://calendaraboutnothing.com" -X OPTIONS HTTP/1.1 204 No Content Access-Control-Allow-Origin: http://calendaraboutnothing.com Access-Control-Allow-Headers: Authorization, X-Requested-With Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE Access-Control-Expose-Headers: Link, X-RateLimit-Limit, X- RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes Access-Control-Max-Age: 86400 Access-Control-Allow-Credentials: true

Slide 88

Slide 88 text

Streaming PATTERN

Slide 89

Slide 89 text

Persistent HTTP

Slide 90

Slide 90 text

Updates as they happen

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

Thanks!