designing api for mobile apps (mobilewarsaw 19.01.2015)

54
Designing mobile API Wojtek Erbetowski MobileWarsaw #21, 19.01.2015 t: @erbetowski

Upload: wojtek-erbetowski

Post on 15-Jul-2015

125 views

Category:

Engineering


3 download

TRANSCRIPT

Page 1: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Designing mobile APIWojtek Erbetowski

MobileWarsaw #21, 19.01.2015t: @erbetowski

Page 2: Designing API for mobile apps (MobileWarsaw 19.01.2015)

About me?You all know me already, right?

Page 3: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Why not simply 'design an API'?

Page 4: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Good mobile API≠

Good API

Page 5: Designing API for mobile apps (MobileWarsaw 19.01.2015)
Page 6: Designing API for mobile apps (MobileWarsaw 19.01.2015)

REST & HATEOAS

Page 7: Designing API for mobile apps (MobileWarsaw 19.01.2015)

GET /users/123{ "name": "John Doe", "age": 25, "links": [ { "rel": "self", "href": "/users/123" }, { "rel": "account", "href": "/accounts/987" }, { "rel": "address", "href": "/addresses/555" } ]}

Page 8: Designing API for mobile apps (MobileWarsaw 19.01.2015)

GET /addresses/555{ "street": "Sesame", "no": 25, "zipCode": "12-321", "state": "NY", "country": "US"}

Page 9: Designing API for mobile apps (MobileWarsaw 19.01.2015)

HATEOAS is great!

Page 10: Designing API for mobile apps (MobileWarsaw 19.01.2015)

there's a thing called latency

Page 11: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Latency

Page 12: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Latency

Page 13: Designing API for mobile apps (MobileWarsaw 19.01.2015)

It can get crazy

Page 14: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Merging responses

Page 15: Designing API for mobile apps (MobileWarsaw 19.01.2015)

GET /user/123{ "name": "John Doe", "age": 25, "country": "US"}

Page 16: Designing API for mobile apps (MobileWarsaw 19.01.2015)

And if it ain't yours?

Page 17: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Expansion FTW!

Page 18: Designing API for mobile apps (MobileWarsaw 19.01.2015)

GET /users/123?fields=[name,age,address[country]]

{ "name": "John Doe", "age": 25, "country": "US"}

Page 19: Designing API for mobile apps (MobileWarsaw 19.01.2015)

but most of all

Page 20: Designing API for mobile apps (MobileWarsaw 19.01.2015)

CONNECTION: KEEP-ALIVE

Page 21: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Docs

Page 22: Designing API for mobile apps (MobileWarsaw 19.01.2015)
Page 23: Designing API for mobile apps (MobileWarsaw 19.01.2015)

THROUGHPUT

Page 24: Designing API for mobile apps (MobileWarsaw 19.01.2015)
Page 25: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Do you get only what you need?

Page 26: Designing API for mobile apps (MobileWarsaw 19.01.2015)

{ "person": { "id": 12345, "firstName": "John", "lastName": "Doe", "age": 25, "phones": { "home": "800-123-4567", "work": "888-555-0000", "cell": "877-123-1234" }, "email": [ "[email protected]", "[email protected]" ], "dateOfBirth": "1980-01-02T00:00:00.000Z", "registered": true, "emergencyContacts": [ { "name": "", "phone": "", "email": "", "relationship": "spouse|parent|child|other" } ], "address": { "street": "Sesame", "no": 25, "zipCode": "12-321", "state": "NY", "country": "US" } }}

Page 27: Designing API for mobile apps (MobileWarsaw 19.01.2015)

{ "firstName": "John", "lastName": "Doe", "age": 25, "country": "US"}

Page 28: Designing API for mobile apps (MobileWarsaw 19.01.2015)

And if it ain't yours?

Page 29: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Expansion FTW!

Page 30: Designing API for mobile apps (MobileWarsaw 19.01.2015)

GET /users/123?fields=[name,age,address[country]]

{ "name": "John Doe", "age": 25, "country": "US"}

Page 31: Designing API for mobile apps (MobileWarsaw 19.01.2015)

DATA COMPRESSION

Page 32: Designing API for mobile apps (MobileWarsaw 19.01.2015)

{"people": [ { "firstName": "Jason", "lastName": "Page", "username": "jasonp", "isMale": true, "phone": "142-808-3743", "nid": "12252671714" ...

Page 33: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Full222910 bytes

GZipped32128 bytes (14%)

Page 34: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Domain complexity

Page 35: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Usually automated testing sucks(on mobile)

Page 36: Designing API for mobile apps (MobileWarsaw 19.01.2015)

So if UI differs fromDATA MODEL

Page 37: Designing API for mobile apps (MobileWarsaw 19.01.2015)

... let the backend guys worry

Page 38: Designing API for mobile apps (MobileWarsaw 19.01.2015)

POST /relation{ "type": "follower", "from": 123, "to": 456}

Page 39: Designing API for mobile apps (MobileWarsaw 19.01.2015)

POST /follow/456

Page 40: Designing API for mobile apps (MobileWarsaw 19.01.2015)

HTTP Cache

Page 41: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Expires: Sat, 21 Feb 2015 05:00 GMT

iOS (AFNetworking + NSURLCache)

Android (Retrofit + OkHttp + HttpResponseCache)

Page 42: Designing API for mobile apps (MobileWarsaw 19.01.2015)

GET /users?page=1[ "Arthur", "Bob", "Celine", "Daniel", "Eve", "Fred", "George"]

Page 43: Designing API for mobile apps (MobileWarsaw 19.01.2015)

GET /users?since=185328145127

Page 44: Designing API for mobile apps (MobileWarsaw 19.01.2015)

{ "items": [ ... ], "next": "/users?since=185328145127"}

Page 45: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Case study

Page 46: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Endpoints overallfrom 36 to 20

Page 47: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Endpoints usage(full application flow)

from 86 to 20

Page 48: Designing API for mobile apps (MobileWarsaw 19.01.2015)

96% data size reduction(84% without GZIP)

Page 49: Designing API for mobile apps (MobileWarsaw 19.01.2015)

In the endit's all about usability

Page 50: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Starring

Page 51: Designing API for mobile apps (MobileWarsaw 19.01.2015)

AkamaiState of the Internethttp://www.akamai.com/stateo!heinternet/

Page 52: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Swaggerhttp://swagger.io/

Page 53: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Applause(Former uTest)

https://itunes.apple.com/us/app/utest/id411486493

Page 54: Designing API for mobile apps (MobileWarsaw 19.01.2015)

Any thoughts?