Data to Go: Mobile API Design
-
Upload
chuck-greb -
Category
Technology
-
view
726 -
download
0
Transcript of Data to Go: Mobile API Design
![Page 1: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/1.jpg)
Mobile API Design
Chuck GrebMobile Platform ArchitectAWeber Communications@ecgreb
Data To Go
![Page 2: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/2.jpg)
I'm an Android guy...
![Page 3: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/3.jpg)
A Brief Survey
![Page 4: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/4.jpg)
An application programming interface (API) is a specification of how software components should interact with each other. In most cases an API is a library that includes specification for routines, data structures, object classes, and variables.
What is an API?
http://en.wikipedia.org/wiki/Application_programming_interface
![Page 5: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/5.jpg)
● Remote (web-based) service● Desktop, laptop, or mobile client● Communication protocol and data model
Remote Service API
![Page 6: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/6.jpg)
Web API Request
![Page 7: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/7.jpg)
Mobile API requests are generally slower and more prone to timeouts and other failures!
Mobile API Request
![Page 8: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/8.jpg)
● Who is your audience?● Is your API open to 3rd party developers?
Public vs. Private APIs
![Page 9: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/9.jpg)
1. Reduce round trips to the server2. Control verbosity3. Restrict access
3 Principles of Mobile API Design
![Page 10: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/10.jpg)
Principle #1Reduce round trips to the server
![Page 11: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/11.jpg)
Resources are limited.
Principle #1Reduce round trips to the server
![Page 12: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/12.jpg)
Mobile resource constraints● battery● bandwidth● memory● cpu
Principle #1Reduce round trips to the server
![Page 13: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/13.jpg)
Eliminate network overhead.
Principle #1Reduce round trips to the server
![Page 14: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/14.jpg)
Brevity trumps discoverability.
Principle #1Reduce round trips to the server
![Page 15: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/15.jpg)
Users are impatient.
Principle #1Reduce round trips to the server
![Page 16: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/16.jpg)
EndpointPOST https://example.com/api/verify_password
Input{"username":"ecgreb", "password":"buddy"}
Output{"success":true}
Example #1Login
![Page 17: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/17.jpg)
EndpointGET https://example.com/api/users/ecgreb
Output{ "user_id":12345 "name":"Chuck Greb" "avatar":"http://example.com/images/image001.jpg" ...}
Example #1Login
![Page 18: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/18.jpg)
EndpointGET https://example.com/api/users/12345/analytics
Output{ "subscribers":47 "unsubscribes":18 "open_rate":0.74468085 "click_rate":0.30882353 ...}
Example #1Login
![Page 19: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/19.jpg)
EndpointPOST https://example.com/api/login
Input{"username":"ecgreb", "password":"buddy"}
Example #1Login
![Page 20: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/20.jpg)
Output{ "user": { "id":12345, "name":"Chuck Greb", "avatar":"http://example.com/images/image001.jpg" }, "analytics": { "subscribers":47, "unsubscribes":18, "open_rate":0.74468085, "click_rate":0.30882353 }, ...}
Example #1Login
![Page 21: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/21.jpg)
Principle #2Control verbosity
![Page 22: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/22.jpg)
Purge empty and irrelevant data.
Principle #2Control verbosity
![Page 23: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/23.jpg)
Pay by the byte.
Principle #2Control verbosity
![Page 24: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/24.jpg)
Use compression.
Principle #2Control verbosity
![Page 25: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/25.jpg)
Specify verbosity level per request.
Principle #2Control verbosity
![Page 26: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/26.jpg)
Object Expansion● Abstract verbosity level● Custom media type● Specify response fields in the request
Principle #2Control verbosity
![Page 27: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/27.jpg)
Abstract verbosity level (1-5)
https://example.com/api/users/12345?verbosity=3
Principle #2Control verbosity
![Page 28: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/28.jpg)
Custom media type
Accept: application/json+user.simple
Principle #2Control verbosity
![Page 29: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/29.jpg)
Specify response fields
https://example.com/api/users/12345?fields=[id,name,avatar]
Principle #2Control verbosity
![Page 30: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/30.jpg)
EndpointGET https://example.com/api/users/12345/messages
Output{"messages": [ { "id":1, "title":"Welcome!", "open_rate":0.74468085, "click_rate":0.30882353 }, ...]}
Example #2Messages
![Page 31: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/31.jpg)
EndpointGET https://example.com/api/users/12345/messages/1
Output{ "id":1, "title":"Welcome!", "open_rate":0.74468085, "click_rate":0.30882353, "recipients": [ {"email":"[email protected]", "name":"Cliff...}, {"email":"[email protected]", "name":Dominic...}, ... ]}
Example #2Messages
![Page 32: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/32.jpg)
Principle #3Restrict access
![Page 33: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/33.jpg)
Identify the source of all incoming requests.
Principle #3Restrict access
![Page 34: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/34.jpg)
Deny unauthorized requests.
Principle #3Restrict access
![Page 35: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/35.jpg)
Protect sensitive data.
Principle #3Restrict access
![Page 36: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/36.jpg)
Use a mobile-friendly security model.
Principle #3Restrict access
![Page 37: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/37.jpg)
EndpointPOST https://example.com/api/login
Input{"username":"ecgreb", "password":"buddy"}
Output{"user": { "id":12345, "name":"Chuck Greb", "avatar":"http://example.com/images/image001.jpg", "access_token":Y2h1Y2tAZXhhbXBsZS5jb20 }, ...}
Example #3Login
![Page 38: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/38.jpg)
1. Reduce round trips to the server2. Control verbosity3. Restrict access
3 Principles of Mobile API Design
![Page 39: Data to Go: Mobile API Design](https://reader033.fdocuments.in/reader033/viewer/2022042700/5556b565d8b42a9c798b5590/html5/thumbnails/39.jpg)
Thank YouQuestions?
Chuck GrebMobile Platform ArchitectAWeber Communications@ecgreb