Data to Go: Mobile API Design

39
Mobile API Design Chuck Greb Mobile Platform Architect AWeber Communications @ecgreb Data To Go

Transcript of Data to Go: Mobile API Design

Page 1: Data to Go: Mobile API Design

Mobile API Design

Chuck GrebMobile Platform ArchitectAWeber Communications@ecgreb

Data To Go

Page 2: Data to Go: Mobile API Design

I'm an Android guy...

Page 3: Data to Go: Mobile API Design

A Brief Survey

Page 4: Data to Go: Mobile API Design

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

● 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

Web API Request

Page 7: Data to Go: Mobile API Design

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

● Who is your audience?● Is your API open to 3rd party developers?

Public vs. Private APIs

Page 9: Data to Go: Mobile API Design

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

Principle #1Reduce round trips to the server

Page 11: Data to Go: Mobile API Design

Resources are limited.

Principle #1Reduce round trips to the server

Page 12: Data to Go: Mobile API Design

Mobile resource constraints● battery● bandwidth● memory● cpu

Principle #1Reduce round trips to the server

Page 13: Data to Go: Mobile API Design

Eliminate network overhead.

Principle #1Reduce round trips to the server

Page 14: Data to Go: Mobile API Design

Brevity trumps discoverability.

Principle #1Reduce round trips to the server

Page 15: Data to Go: Mobile API Design

Users are impatient.

Principle #1Reduce round trips to the server

Page 16: Data to Go: Mobile API Design

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

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

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

EndpointPOST https://example.com/api/login

Input{"username":"ecgreb", "password":"buddy"}

Example #1Login

Page 20: Data to Go: Mobile API Design

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

Principle #2Control verbosity

Page 22: Data to Go: Mobile API Design

Purge empty and irrelevant data.

Principle #2Control verbosity

Page 23: Data to Go: Mobile API Design

Pay by the byte.

Principle #2Control verbosity

Page 24: Data to Go: Mobile API Design

Use compression.

Principle #2Control verbosity

Page 25: Data to Go: Mobile API Design

Specify verbosity level per request.

Principle #2Control verbosity

Page 26: Data to Go: Mobile API Design

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

Abstract verbosity level (1-5)

https://example.com/api/users/12345?verbosity=3

Principle #2Control verbosity

Page 28: Data to Go: Mobile API Design

Custom media type

Accept: application/json+user.simple

Principle #2Control verbosity

Page 29: Data to Go: Mobile API Design

Specify response fields

https://example.com/api/users/12345?fields=[id,name,avatar]

Principle #2Control verbosity

Page 30: Data to Go: Mobile API Design

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

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

Principle #3Restrict access

Page 33: Data to Go: Mobile API Design

Identify the source of all incoming requests.

Principle #3Restrict access

Page 34: Data to Go: Mobile API Design

Deny unauthorized requests.

Principle #3Restrict access

Page 35: Data to Go: Mobile API Design

Protect sensitive data.

Principle #3Restrict access

Page 36: Data to Go: Mobile API Design

Use a mobile-friendly security model.

Principle #3Restrict access

Page 37: Data to Go: Mobile API Design

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

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

Thank YouQuestions?

Chuck GrebMobile Platform ArchitectAWeber Communications@ecgreb