Your SlideShare is downloading. ×
0
API Reliability Guidehttp://www.flickr.com/photos/erreeffe/3769670873/                                                    ...
Nick DeNardisAssociate Director of Web Communicationsat Wayne State Universityhttp://wayne.edu/Host of EDU Checkuphttp://e...
DisclaimerSome assembly required.
APIApplication Programming Interface
Not just for robotshttp://www.flickr.com/photos/stevent/3241986538/
Value Chainhttp://apigee.com/
The API’s job is to                                                                       make the                        ...
It makes the user experience         can breakhttp://www.flickr.com/photos/daychokesnight/2149714792/
Too slow...http://www.flickr.com/photos/toolmantim/6170448143/
Too complicated...http://www.flickr.com/photos/toolmantim/6170448143/
Adds a layerhttp://www.flickr.com/photos/jabb/6715983809/
Complications with     mobile      “always on”
Mobile isn’t        going anywhere              1.45 Million devices per day                 371,000 births per dayhttp://...
Mobile Data Traffic Expected To Rise 40-                        Fold Over Next Five Yearshttp://techcrunch.com/2010/03/30/m...
Mobile users usemore bandwidth
Desktop250 kb - Avg page weight2.5 pages - Avg number per visit   1300625 kb - Bandwidth per visit        975             ...
Mobile                 Desktop              40              30Millions of visitors     20              10               0 ...
The mobile Web is slow     And it’s mostly our fault
You can’t blame the network for everything     CSS                              Images   Images                           ...
Do less better
One size != fit allhttps://api.twitter.com/1/https://us2.api.mailchimp.com/1.3/https://api.foursquare.com/v2/https://api.i...
SOAP                                                 RESTThe request:                                         The request:...
Stick to REST
XML suckshttp://www.flickr.com/photos/philmanker/3654636770/
Your best friend               JSONEasy to encode:$arr = array(a => 1, b => 2, c => 3, d => 4, e => 5);json_encode($arr);E...
Existing Resourceshttp://doteduguru.com/id7800-results-higher-ed-cms-usage-survey-2011.html
Flattened highed = More interfaces           CRM           CMS         iModules          Events     Course Schedule       ...
Your data is everywhere                                          WebsiteCMS         Gather &          Clean               ...
API is the glue                                           WebsiteCMS          Gather &           Clean                    ...
Rolling your own       API     Trust no one.
Making the glue               Ingredients:Server space you controlapi.domain.edu or domain.edu/apiAbility:  • Database  • ...
Getting data closer
Documentation                                                         Designhttp://www.flickr.com/photos/edublogger/695096...
Affordance                     The physical design will communicate how it                                is suppose to be...
/getNews/getNewsReleases/findPeople/getPerson/eventsList/eventInfo/eventRSVP/classSearch/semesterList/parkingLotList/parki...
Create. Read. Update. Delete.http://www.flickr.com/photos/fss/2181882493/
Read first.http://www.flickr.com/photos/hackaday/4425372655/
GET /academic/colleges/listing   GET /academic/colleges/info/150REST                                       Item Category  ...
GET /academic/colleges/listingGET /academic/colleges/infoGET /academic/majors/listingGET /academic/majors/infoGET /academi...
The devil is in the details Simple URLResponse code Total countData container    Keep it lightweight                 91 KB
Use only what you need FiltersLess data            41 KB
Writing data
POST /admissions/rfi/addPOST /admissions/visit/addPOST /admissions/application/addPOST /academic/colleges/addPOST /academi...
Soft Delete (keep all the data!)
POST /academic/colleges/removePOST /academic/majors/removePOST /academic/classes/removePOST /parking/availability/removePo...
Authentication    /api/user/auth
Auth workflowRequest       API Key         Rate Limit                         Username/Pass     Session IDCheck Credential...
Rate Limiting 100 per minute per Key/IP
Cache. Cache.   Cache.
Professional cachehttp://www.flickr.com/photos/carlos/2417032795/
APC<?php$bar = BAR;apc_store(foo, $bar);var_dump(apc_fetch(foo));?>
Static Cachehttp://www.flickr.com/photos/basic_sounds/5779597720/
Static files<?phpif ((is_file($_SERVER[SCRIPT_FILENAME]..json))   && (time()-filemtime($_SERVER[SCRIPT_FILENAME]..json) < ...
HTML5                                       localStorageif (typeof(localStorage) == undefined ) {    alert(Your browser do...
JSONPfunction handle_data(data) {   // `data` is now the object representation of the JSON data}---http://some.tld/web/ser...
Expires header        <?php        header(Expires: .gmdate(D, d M Y H:i:s GMT, time() + 3600));        ?>1 Month          ...
Our StatsFeb 2011 - In production6.1 million requests48% from mobile  21% iOS  23% Android  66% Web95% GET’s16 ms average ...
Examples
Mobile news
maps/locations/listingGoogle API                  events/event/listing             directory/people/listing             ac...
maps/category/listing                           events/event/listing                        maps/location/info
faculty/profile/info                      go/url/info
Hackathon                                                 Community through datahttp://www.flickr.com/photos/hackny/5684887...
Resources•   http://apigee.com/•   http://rubyonrails.org/•   http://cakephp.org/•   https://groups.google.com/group/api-c...
Hackathons•   http://dschool.stanford.edu/blog/2012/01/27/hack-d-kicks-off-more-than-a-    dozen-projects-underway/•   htt...
Questions?  Don’t be shy.
Thank You              @nickdenardis        nick.denardis@gmail.com        http://nickdenardis.com/https://speakerdeck.com...
API Reliability Guide
API Reliability Guide
Upcoming SlideShare
Loading in...5
×

API Reliability Guide

2,216

Published on

Creating a separate mobile website is a great idea until someone changes a data source on you. Your users don’t care if your LDAP is down or why they can’t pull up next the class schedule for next semester. In this session you will learn how to plan for the worst; network outages, slow response times and unorganized data. The mobile Web isn’t very useful without content and often that content is gathered from many sources that are out of the developers control. Gathering, protecting and organizing that data is the job of a smart developer and a successful mobile Web presence. This is accomplished by adding an API layer to everything you do. This session will walk you through the ins and outs of creating and maintaining a Web API that can extend far beyond your mobile presence.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,216
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
21
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "API Reliability Guide"

  1. 1. API Reliability Guidehttp://www.flickr.com/photos/erreeffe/3769670873/ @nickdenardis / #psuweb12
  2. 2. Nick DeNardisAssociate Director of Web Communicationsat Wayne State Universityhttp://wayne.edu/Host of EDU Checkuphttp://educheckup.com/Curator of EDU Snippitshttp://edusnippits.com/Writer for .eduGuruhttp://doteduguru.com/
  3. 3. DisclaimerSome assembly required.
  4. 4. APIApplication Programming Interface
  5. 5. Not just for robotshttp://www.flickr.com/photos/stevent/3241986538/
  6. 6. Value Chainhttp://apigee.com/
  7. 7. The API’s job is to make the developer as successful as possiblehttp://knowyourmeme.com/memes/i-hate-sandcastles-success-kid
  8. 8. It makes the user experience can breakhttp://www.flickr.com/photos/daychokesnight/2149714792/
  9. 9. Too slow...http://www.flickr.com/photos/toolmantim/6170448143/
  10. 10. Too complicated...http://www.flickr.com/photos/toolmantim/6170448143/
  11. 11. Adds a layerhttp://www.flickr.com/photos/jabb/6715983809/
  12. 12. Complications with mobile “always on”
  13. 13. Mobile isn’t going anywhere 1.45 Million devices per day 371,000 births per dayhttp://www.lukew.com/ff/entry.asp?1506
  14. 14. Mobile Data Traffic Expected To Rise 40- Fold Over Next Five Yearshttp://techcrunch.com/2010/03/30/mobile-data-traffic-rise-40-fold/
  15. 15. Mobile users usemore bandwidth
  16. 16. Desktop250 kb - Avg page weight2.5 pages - Avg number per visit 1300625 kb - Bandwidth per visit 975 650Mobile 32550 kb - Avg page weight25 pages - Avg number per visit 0 Data Desktop Mobile1.25 mb - Bandwidth per visit
  17. 17. Mobile Desktop 40 30Millions of visitors 20 10 0 2009 2010 2011 2012 2013 2014 2015 2016 2017 http://wayne.edu/
  18. 18. The mobile Web is slow And it’s mostly our fault
  19. 19. You can’t blame the network for everything CSS Images Images New Content Javascript Initial HTML Cell Latency Cell Latency Time Time First Request Second Request
  20. 20. Do less better
  21. 21. One size != fit allhttps://api.twitter.com/1/https://us2.api.mailchimp.com/1.3/https://api.foursquare.com/v2/https://api.instagram.com/v1/https://www.salesforce.com/services/Soap/c/18.0https://api.wayne.edu/v1/ Think versioning from the start
  22. 22. SOAP RESTThe request: The request:GET /StockPrice HTTP/1.1 GET /StockPrice/IBM HTTP/1.1Host: example.org Host: example.orgContent-Type: application/soap+xml; charset=utf-8 Accept: text/xmlContent-Length: nnn Accept-Charset: utf-8<?xml version="1.0"?> The response:<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" HTTP/1.1 200 OK xmlns:s="http://www.example.org/stock-service"> Content-Type: text/xml; charset=utf-8 <env:Body> Content-Length: nnn <s:GetStockQuote> <s:TickerSymbol>IBM</s:TickerSymbol> <?xml version="1.0"?> </s:GetStockQuote> <s:Quote xmlns:s="http://example.org/stock- </env:Body> service"></env:Envelope> <s:TickerSymbol>IBM</s:TickerSymbol> <s:StockPrice>45.25</s:StockPrice>The response: </s:Quote>HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version="1.0"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:s="http://www.example.org/stock-service"> <env:Body> <s:GetStockQuoteResponse> <s:StockPrice>45.25</s:StockPrice> </s:GetStockQuoteResponse> </env:Body></env:Envelope> 4 kb vs 2 kb Round Trip
  23. 23. Stick to REST
  24. 24. XML suckshttp://www.flickr.com/photos/philmanker/3654636770/
  25. 25. Your best friend JSONEasy to encode:$arr = array(a => 1, b => 2, c => 3, d => 4, e => 5);json_encode($arr);Easy to decode:$json = {"a":1,"b":2,"c":3,"d":4,"e":5};json_decode($json);Javascript:var myObject = eval(( + json + )); Douglas Crockford
  26. 26. Existing Resourceshttp://doteduguru.com/id7800-results-higher-ed-cms-usage-survey-2011.html
  27. 27. Flattened highed = More interfaces CRM CMS iModules Events Course Schedule Parking Flickr YouTube Faculty Profiles Library Catalog
  28. 28. Your data is everywhere WebsiteCMS Gather & Clean Mobile WebsiteEvents Shadow storage Mobile AppLDAP API Webserver Digital SignageBanner Third Party
  29. 29. API is the glue WebsiteCMS Gather & Clean Mobile WebsiteEvents Shadow storage Mobile AppLDAP API Webserver Digital SignageBanner Third Party
  30. 30. Rolling your own API Trust no one.
  31. 31. Making the glue Ingredients:Server space you controlapi.domain.edu or domain.edu/apiAbility: • Database • Cronjobs • Server logs • Analytics • PHP accelerator • Xdebug
  32. 32. Getting data closer
  33. 33. Documentation Designhttp://www.flickr.com/photos/edublogger/6950969837/
  34. 34. Affordance The physical design will communicate how it is suppose to be usedhttp://www.flickr.com/photos/hawkexpress/269032594/
  35. 35. /getNews/getNewsReleases/findPeople/getPerson/eventsList/eventInfo/eventRSVP/classSearch/semesterList/parkingLotList/parkingAvailable
  36. 36. Create. Read. Update. Delete.http://www.flickr.com/photos/fss/2181882493/
  37. 37. Read first.http://www.flickr.com/photos/hackaday/4425372655/
  38. 38. GET /academic/colleges/listing GET /academic/colleges/info/150REST Item Category Function Interface (Class)
  39. 39. GET /academic/colleges/listingGET /academic/colleges/infoGET /academic/majors/listingGET /academic/majors/infoGET /academic/classes/listingGET /academic/classes/infoGET /parking/availability/listingGET /parking/availability/info
  40. 40. The devil is in the details Simple URLResponse code Total countData container Keep it lightweight 91 KB
  41. 41. Use only what you need FiltersLess data 41 KB
  42. 42. Writing data
  43. 43. POST /admissions/rfi/addPOST /admissions/visit/addPOST /admissions/application/addPOST /academic/colleges/addPOST /academic/colleges/editPOST /academic/majors/addPOST /academic/majors/editPost data:id=3047
  44. 44. Soft Delete (keep all the data!)
  45. 45. POST /academic/colleges/removePOST /academic/majors/removePOST /academic/classes/removePOST /parking/availability/removePost data:id=3047
  46. 46. Authentication /api/user/auth
  47. 47. Auth workflowRequest API Key Rate Limit Username/Pass Session IDCheck Credentials Session ID(Do work) Return
  48. 48. Rate Limiting 100 per minute per Key/IP
  49. 49. Cache. Cache. Cache.
  50. 50. Professional cachehttp://www.flickr.com/photos/carlos/2417032795/
  51. 51. APC<?php$bar = BAR;apc_store(foo, $bar);var_dump(apc_fetch(foo));?>
  52. 52. Static Cachehttp://www.flickr.com/photos/basic_sounds/5779597720/
  53. 53. Static files<?phpif ((is_file($_SERVER[SCRIPT_FILENAME]..json)) && (time()-filemtime($_SERVER[SCRIPT_FILENAME]..json) < 3600)) readfile($_SERVER[SCRIPT_FILENAME]..json); exit; }// (the php script itself goes here)echo $response;$fp = fopen($_SERVER[SCRIPT_FILENAME]..json, w);fwrite($fp, $response);fclose($fp);?>
  54. 54. HTML5 localStorageif (typeof(localStorage) == undefined ) { alert(Your browser does not support HTML5 localStorage. Try upgrading.);} else { try { localStorage.setItem("name", "Hello World!"); //saves to the database, } catch (e) { if (e == QUOTA_EXCEEDED_ERR) { alert(Quota exceeded!); //data wasnt successfully saved due to quota exceedso throw an error } } document.write(localStorage.getItem("name")); //Hello World! localStorage.removeItem("name"); //deletes the matching item from the database}http://paperkilledrock.com/2010/05/html5-localstorage-part-one/
  55. 55. JSONPfunction handle_data(data) { // `data` is now the object representation of the JSON data}---http://some.tld/web/service?callback=handle_data:---handle_data({"data_1": "hello world", "data_2":["the","sun","is","shining"]});
  56. 56. Expires header <?php header(Expires: .gmdate(D, d M Y H:i:s GMT, time() + 3600)); ?>1 Month 1 Week 1 DaySemesters Courses EventsSubjects Media Experts NewsDegreesMap Categories No CacheMap Locations Course Availability Parking Availability
  57. 57. Our StatsFeb 2011 - In production6.1 million requests48% from mobile 21% iOS 23% Android 66% Web95% GET’s16 ms average response time
  58. 58. Examples
  59. 59. Mobile news
  60. 60. maps/locations/listingGoogle API events/event/listing directory/people/listing academic/courses/listing
  61. 61. maps/category/listing events/event/listing maps/location/info
  62. 62. faculty/profile/info go/url/info
  63. 63. Hackathon Community through datahttp://www.flickr.com/photos/hackny/5684887983/
  64. 64. Resources• http://apigee.com/• http://rubyonrails.org/• http://cakephp.org/• https://groups.google.com/group/api-craft/• http://37signals.com/svn/posts/3018-api-design-for-humans• http://broadcast.oreilly.com/2011/06/the-good-the-bad-the-ugly-of-rest- apis.html• http://sixrevisions.com/html/introduction-web-storage/• http://webcomm.fiu.edu/2011/11/json-as-an-api-tool-and-why-its-awesome/• http://doteduguru.com/id4579-results-higher-ed-cms-usage.html
  65. 65. Hackathons• http://dschool.stanford.edu/blog/2012/01/27/hack-d-kicks-off-more-than-a- dozen-projects-underway/• http://civic.mit.edu/blog/schock/occupydata-hackathon-2-roundup• http://newmed.media.mit.edu/health-and-wellness-innovation-2012• http://nyuad.nyu.edu/hackathon/about/• http://startup.berkeley.edu/hackathon/• http://www.njit.edu/hackathon/• http://www.lib.umich.edu/art-architecture-engineering-library/ announcements/48-hour-mobile-app-hackathon
  66. 66. Questions? Don’t be shy.
  67. 67. Thank You @nickdenardis nick.denardis@gmail.com http://nickdenardis.com/https://speakerdeck.com/u/nickdenardis
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×