Creating an Effective Mobile API
-
Upload
nick-denardis -
Category
Technology
-
view
2.134 -
download
2
description
Transcript of Creating an Effective Mobile API
![Page 1: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/1.jpg)
Creating API’s for MobileNick DeNardis
![Page 2: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/2.jpg)
@nickdenardis
Associate Director of Web Communications Wayne State Universityhttp://wayne.edu/
Host of EDU Checkuphttp://educheckup.com/
Curator of EDU Snippitshttp://edusnippits.com/
Writer for .eduGuruhttp://doteduguru.com/
![Page 3: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/3.jpg)
Disclaimer
This talk is less about how to code an API but more about the strategy behind creating a flexible and resilient API.
![Page 4: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/4.jpg)
API:Application programming interface
![Page 5: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/5.jpg)
Not just for robots.http://www.flickr.com/photos/stevent/3241986538/
![Page 6: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/6.jpg)
The API’s job is to make the developer as successful as possible
http://knowyourmeme.com/memes/i-hate-sandcastles-success-kid
![Page 7: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/7.jpg)
Where isn’t it useful?
http://www.flickr.com/photos/daychokesnight/2149714792/
![Page 8: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/8.jpg)
Too slow...
http://www.flickr.com/photos/toolmantim/6170448143/
![Page 9: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/9.jpg)
Too complicated...http://www.flickr.com/photos/toolmantim/6170448143/
![Page 10: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/10.jpg)
Adds a layer
http://www.flickr.com/photos/jabb/6715983809/
![Page 11: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/11.jpg)
Complications with mobile“always on”
![Page 12: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/12.jpg)
Mobile isn’t going anywhere
1.45 Million devices per day371,000 births per day
http://www.lukew.com/ff/entry.asp?1506
![Page 13: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/13.jpg)
Mobile Data Traffic Expected To Rise 40-Fold Over Next Five Years
http://techcrunch.com/2010/03/30/mobile-data-traffic-rise-40-fold/
![Page 14: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/14.jpg)
250 kb - Avg page weight2.5 pages - Avg number per visit
625 kb - Bandwidth per visit
Desktop
50 kb - Avg page weight25 pages - Avg number per visit
1.25 mb - Bandwidth per visit
Mobile
0
325
650
975
1300
Data
Desktop Mobile
![Page 15: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/15.jpg)
0
10
20
30
40
2009 2010 2011 2012 2013 2014 2015 2016 2017
Mobile Desktop
Millions of visitors
http://wayne.edu/
![Page 16: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/16.jpg)
The Mobile Web is SlowAnd it’s mostly our fault
![Page 17: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/17.jpg)
Time
Cell Latency
Initial HTML
Javascript
Images
CSS
You can’t blame the network for everything
![Page 18: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/18.jpg)
Time
Cell Latency
New Content
Images
Second Request
![Page 19: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/19.jpg)
Do less better
![Page 20: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/20.jpg)
One size != fit all
Think versioning from the start
https://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/
![Page 21: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/21.jpg)
SOAPThe request:
GET /StockPrice HTTP/1.1Host: example.orgContent-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:GetStockQuote> <s:TickerSymbol>IBM</s:TickerSymbol> </s:GetStockQuote> </env:Body></env:Envelope>
The response:
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>
The request:
GET /StockPrice/IBM HTTP/1.1Host: example.orgAccept: text/xmlAccept-Charset: utf-8
The response:
HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Content-Length: nnn
<?xml version="1.0"?><s:Quote xmlns:s="http://example.org/stock-service"> <s:TickerSymbol>IBM</s:TickerSymbol> <s:StockPrice>45.25</s:StockPrice></s:Quote>
REST
4 kb vs 2 kbRound Trip
![Page 22: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/22.jpg)
Stick to REST
![Page 23: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/23.jpg)
XML suckshttp://www.flickr.com/photos/philmanker/3654636770/
![Page 24: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/24.jpg)
Your best friend JSON
Easy 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 + ')');
![Page 25: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/25.jpg)
Existing Resources
http://doteduguru.com/id7800-results-higher-ed-cms-usage-survey-2011.html
![Page 26: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/26.jpg)
Not everything is in the CMS
CMS
Events
LDAP
Banner
Gather & Clean
Shadow storage
API Webserver
Website
Mobile Website
Mobile App
Digital Signage
Third Party
![Page 27: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/27.jpg)
Rolling your own APITrust no one.
![Page 28: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/28.jpg)
Create. Read. Update. Delete.
http://www.flickr.com/photos/fss/2181882493/
![Page 29: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/29.jpg)
Start with a map
http://www.flickr.com/photos/56684679@N08/6155875352/
![Page 30: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/30.jpg)
Read first.
http://www.flickr.com/photos/hackaday/4425372655/
![Page 31: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/31.jpg)
GET /academic/colleges/listingGET /academic/colleges/info
GET /academic/majors/listingGET /academic/majors/info
GET /academic/classes/listingGET /academic/classes/info
GET /parking/availability/listingGET /parking/availability/info
![Page 32: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/32.jpg)
The devil is in the details
Simple URL
Response code
Total count
Data container
Keep it lightweight
91 KB
![Page 33: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/33.jpg)
Use only what you need
Filters
Less data
41 KB
![Page 34: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/34.jpg)
Writing data
![Page 35: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/35.jpg)
POST /admissions/rfi/addPOST /admissions/visit/addPOST /admissions/application/add
POST /academic/colleges/addPOST /academic/colleges/edit
POST /academic/majors/addPOST /academic/majors/edit
![Page 36: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/36.jpg)
Soft Delete(keep all the data!)
![Page 37: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/37.jpg)
POST /academic/colleges/remove
POST /academic/majors/remove
POST /academic/classes/remove
POST /parking/availability/remove
![Page 38: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/38.jpg)
Authentication/api/user/auth
![Page 39: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/39.jpg)
Cache. Cache. Cache.
![Page 40: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/40.jpg)
Professional cache
http://www.flickr.com/photos/carlos/2417032795/
![Page 41: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/41.jpg)
APC
<?php$bar = 'BAR';apc_store('foo', $bar);var_dump(apc_fetch('foo'));?>
![Page 42: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/42.jpg)
Ghetto cache
http://www.flickr.com/photos/basic_sounds/5779597720/
![Page 43: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/43.jpg)
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);
?>
![Page 44: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/44.jpg)
if (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 wasn't successfully saved due to quota exceed so 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/
HTML5 localStorage
![Page 45: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/45.jpg)
Expires header<?php header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));?>
SemestersSubjectsDegreesMap CategoriesMap Locations
1 Month
CoursesMedia Experts
1 Week
Course AvailabilityParking Availability
No Cache
EventsNews
1 Day
![Page 46: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/46.jpg)
Our StatsFeb 2011 - In production2.5 million requests
48% from mobile21% iOS23% Android66% Web
95% GET’s16 ms average response time
![Page 47: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/47.jpg)
Examples
![Page 48: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/48.jpg)
Mobile news
![Page 49: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/49.jpg)
Google APImaps/locations/listing
events/event/listing
directory/people/listing
academic/courses/listing
![Page 50: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/50.jpg)
maps/category/listing
maps/location/info
events/event/listing
![Page 51: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/51.jpg)
faculty/profile/info
go/url/info
![Page 52: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/52.jpg)
HackathonCommunity through data
http://www.flickr.com/photos/hackny/5684887983/
![Page 53: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/53.jpg)
Resources• http://apigee.com/
• http://rubyonrails.org/
• http://cakephp.org/
• 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
![Page 54: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/54.jpg)
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
![Page 55: Creating an Effective Mobile API](https://reader034.fdocuments.in/reader034/viewer/2022042521/547b26d2b379597b2b8b4cc3/html5/thumbnails/55.jpg)
Questions?Don’t be shy.