5-5-2014 - api days - documentationless api

24
EyeEm Ramzi Rizk @ramz Designing a documentation-less API Rino Montiel @rinoFM

Transcript of 5-5-2014 - api days - documentationless api

Page 1: 5-5-2014 - api days - documentationless api

EyeEm

Ramzi Rizk @ramz

Designing a documentation-less API

Rino Montiel @rinoFM

Page 2: 5-5-2014 - api days - documentationless api

EyeEm is the world’s premier community and marketplace for the photographer inside all of us

Page 3: 5-5-2014 - api days - documentationless api
Page 4: 5-5-2014 - api days - documentationless api

API V2

• REST!• Read Only!• Anonymous and Authenticated access!• JSON response

we eat our own dog food.

Page 5: 5-5-2014 - api days - documentationless api

END OF LIFECYCLE

Page 6: 5-5-2014 - api days - documentationless api

6

https://api.eyeem.com/v2/photos/12345?detailed=1&friends=1&totalFriends=10&likes=1&totalLikers=20&albums=1&detailedAlbums=1&albumPhotos=1&commentType=detailed…..

Why rewrite?

Page 7: 5-5-2014 - api days - documentationless api

7

• Intuitive!• Flexible!• Verbose!• Discoverable

Why rewrite?

Page 8: 5-5-2014 - api days - documentationless api

API V3

Page 9: 5-5-2014 - api days - documentationless api

9

• RESTFUL: correct use of nouns / verbs!• standard pagination sequencing on

pagination response after={unique_id},limit=X!

!• consistent parameters

sort ={time || popular} type ={nearby || popular …} ll =52.2513,13.3425 order ={asc || desc} query ={string}

Intuitive

Page 10: 5-5-2014 - api days - documentationless api

10

• Optimized for native apps!• Versioning (qualifier OR uri)!• “fields” param allows granular control of response

contentusers/{id}?fields=id,nickname,group(photos:10)

Flexible

Page 11: 5-5-2014 - api days - documentationless api

11

• meta object in all responses!• http code in header and body!• custom error code w/ link in body!• custom message in body

Verbose

{ “meta”:{ “http_code”:200, “message”:“deprecated endpoint”, “error_code”:123, “error_url”:“https://www.github.com/eyeem/api/wiki/error_123” } “data”:{ … } }

Page 12: 5-5-2014 - api days - documentationless api

12

• Self-documenting API!• Restful objects (1)!• automation, inline shema!

• HATEOAS (2)(3)!• really “surf” the api.

Discoverable

http://restfulobjects.org/!http://www.slideshare.net/josdirksen/rest-from-get-to-hateoas!http://en.wikipedia.org/wiki/HATEOAS

Page 13: 5-5-2014 - api days - documentationless api

13

Find a user and follow the first person to like their latest photo

Example

Page 14: 5-5-2014 - api days - documentationless api

14

https://api.eyeem.com/v3{ "links": [ { "rel": "search", "href": "http://api.eyeem.com/api/v3/search" }, { "rel": "users", "href": "http://api.eyeem.com/api/v3/users" }, … { "rel": "photos", "href": "http://api.eyeem.com/api/v3/photos" } ] }

Page 15: 5-5-2014 - api days - documentationless api

15

https://api.eyeem.com/v3/search

{ "search": { "params": [ "type", "query", "fields" ] }, "links": [ { "rel": "self", "href": "http://api.eyeem.com/api/v3/search" } ] }

Page 16: 5-5-2014 - api days - documentationless api

16

/search?type=user&q=ramz&fields=id,nickname

{ "search": { "result": [ { "id": "1013", "nickname": “ramz", "links": [ { "rel": "user", "href": "https://api.eyeem.com/api/v3/users/ramz" } ] } ] } }

Page 17: 5-5-2014 - api days - documentationless api

17

{ "user": { "id": "1013", "nickname": "ramz", "fullname": "Ramzi Rizk", "links": [ { "rel": "self", "href": "http://api.eyeem.com/api/v3/users/1013" }, { "rel": "photos", "href": "http://api.eyeem.com/api/v3/users/1013/photos" } ] } }

/users/ramz

Page 18: 5-5-2014 - api days - documentationless api

18

/users/ramz/photos?sort=time&order=desc{ "photos": { "limit": 1, "total": 2238, "items": [ { "id": "36373973", "updated": "2014-05-03T17:14:00+0200", "links": [ { "rel": "self", "href": "http://api.eyeem.com/api/v3/photos/36373973" } ] } ] } }

Page 19: 5-5-2014 - api days - documentationless api

19

/photos/36373973{ "photo": { "id": "36373973", "updated": "2014-05-03T17:14:00+0200", "links": [ { "rel": "albums", "href": "http://api.eyeem.com/api/v3/photos/36373973/albums" }, { "rel": "likers", "href": "http://api.eyeem.com/api/v3/photos/36373973/likers" } ] } }

Page 20: 5-5-2014 - api days - documentationless api

20

{ "likers": { "limit": 1, "total": 51, "items": [ { "id": "3097120", "nickname": “rinofm", "links": [ { "rel": "user", "href": "https://api.eyeem.com/api/v3/users/rinofm" } ] } ] } }

/photos/36373973/likers?sort=time&order=asc&limit=1

Page 21: 5-5-2014 - api days - documentationless api

21

/users/rinofm{ "user": { "id": "3097120", "nickname": "rinofm", "links": [ { "rel": "self", "href": "http://api.eyeem.com/api/v3/users/3097120" }, { "rel": "followers", "href": “http://api.eyeem.com/api/v3/users/3097120/followers}“ }, ] } }}

Page 22: 5-5-2014 - api days - documentationless api

22

{ "meta": { “http_code”:200, “message”:“ramz now follows rinofm” }, "data": { "followers": { "limit": 1, "total": 2986, "items": [ { "id": "1013", "nickname": “ramz" } ] } } }

PUT /users/rinofm/followers/me

Page 23: 5-5-2014 - api days - documentationless api

23

Performance !& !

Speed

Food for thought

Perfection !&!

SpecificationsVS