View
125
Download
0
Category
Preview:
Citation preview
DESIGN MOBILE
APIs
EFFICIENT
Mobile Is Present & Future
Think About Mobile Data Traffic
But What’s The Problem With Mobile?
A Mobile Device is Low Powered Low BandwidthRuns On Battery
Bandwidth Matters….Desktop:
250 kb – Avg. Page Weight2.5 pages – Avg. number Per Visit
Total = 625 Kb Bandwidth Per Visit
Mobile: 100 kb – Avg. Page Weight10 pages- Avg. number per visit
Total = 1 Mb Bandwidth per visit
We want to keep the best user experience at all time.Nobody wants an unresponsive app.
The efficient API make a huge Impact on Performance for Mobile App Specially.
When the API is too lazy or Incomplete the burden is put on the mobile App.
Any Workaround for it, put stress on the app which consumes too much resources.
Mobile Users are very Impatient…
Where It Fails??
Too Slow Too Much Complicated to Parse Dependent on 3rd Party Data is not Cache DB is not efficient like Indexing DB Query is not Efficient like Join
How To Solved??
Be Simple Be Fast Use of Caching Load Needed Data Only Think as Service not as Methods
Version API from the beginning
Easy to maintain API Easy to make changes in API & Debugging Easy to add , remove or change Functionality Enable user for backward support API becomes more reliable
Use Pagination
Use LIMIT & OFFSET Enable Flexibility for User Data is Less & API becomes FAST
E.g. GET /properties?offset=10&limit=5
Avoid Unnecessary Steps…
E.g. For Login API
1) Passing Credential & Get Session Token2) Get User Data after passing Valid Session Token
Instead Of This
Check Credential & Pass Data with Session TokenSession Token will use by future API Calls
Combine Requests & Responses
E.g. Application Start up
Think when multiple APIs calls on Application Start up
Hard to Maintain & Parse If some API calls fails
Instead Of This
Combine Multiple request into Single
Easy to Maintain & Parse Easy to Handle Failure
Field Selection
Mobile shows very less attributes on the screen.It don’t require all the fields.Fields Selection gives ability to API consumer to get desire data
E.g.
GET /cars?fields=manufacturer,model,id,color
Authentication
Secure Data Transit Secure your Data while changing by API Use Access Token Malicious data having unintended consequences
Load Only Needed Data
Load Data which are need to Display Load Images,files Asynchronously It affects Latency Time of API It affects User Experience Avoids unnecessary condition checking saves User Time saves User Data charge Amount
Error With Information Helps in Debug Error Use standard format that Self Explanatory Helps in Recovery from failure
E.g.
{ "http_code": "401", “User_message" : “Email does not exits", "internal_message" : “Authentication Failed" }
Status Code Value Meaning200 OK Working fine201 OK New resource
Created204 OK Successfully
Deleted
304 Not Modified Use Cache Data
400 Bad Request Invalid401 Unauthorized Authentication
Failed 403 Forbidden Refuse Request404 Not Found No resource
500 Internal Server Error
Server Error
Awesome Documentation
Might be hardest job It should be precise, correct & easy to understand Update when API changes made Saves lots of time in implementation Show sample code Better for future
Thank You…
Recommended