Slide 1

Slide 1 text

REST Clients

Slide 2

Slide 2 text

CTO at Redbooth ! @masylum on both Github and Twitter

Slide 3

Slide 3 text

• Tasks • Conversations • Documents and files • Chat

Slide 4

Slide 4 text

• Web Client • iOS Client • Android Client • GMail and Outlook plugins

Slide 5

Slide 5 text

One API to rule them all

Slide 6

Slide 6 text

Business development “for free”

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Drawbacks?

Slide 9

Slide 9 text

• Render on the client • More Integration test • Backward compatibility • Coordinate API and client implementations

Slide 10

Slide 10 text

REST is not dead despite exaggerated hypermedia rumors

Slide 11

Slide 11 text

REST tells you how to build and consume your API

Slide 12

Slide 12 text

Constraints set you free

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Development in parallel

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Beware!

Slide 18

Slide 18 text

Stateful is hard: Server and client’s state will diverge

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Side effects? Can be RESTful too

Slide 21

Slide 21 text

Use POST for RPC actions ! http://restful-api-design.readthedocs.org/ en/latest/methods.html#actions

Slide 22

Slide 22 text

POST /api/3/channels/9/mute HTTP/1.1 Host: redbooth.com ! { “for”: “1-hour” } ! Simplified Response ! {“id”: 9, “muted_until": 1413735462} !

Slide 23

Slide 23 text

Use the Link HTTP header to tell the client to re-fetch a resource http://www.w3.org/wiki/LinkHeader

Slide 24

Slide 24 text

POST /api/3/comments HTTP/1.1 Host: redbooth.com ! { “body”: “This task is for @bpedro” } ! Response Contains ! Link:; rel="updated" type="Task">

Slide 25

Slide 25 text

Minimize impact of race conditions with PATCH instead of PUT

Slide 26

Slide 26 text

You are using PATCH wrong. Try JSON-MERGE ! http://tools.ietf.org/html/draft- ietf-appsawg-json-merge-patch-07

Slide 27

Slide 27 text

PATCH /my/resource HTTP/1.1 Host: example.org Content-Type: application/merge-patch+json ! { "title": "Hello!", "author": { "familyName": null } }

Slide 28

Slide 28 text

For complex resources try JSON-PATCH ! http://tools.ietf.org/html/rfc6902

Slide 29

Slide 29 text

PATCH /my/resource HTTP/1.1 Host: example.org Content-Type: application/json-patch+json ! [ { "op": "remove", "path": "/a/b/c" }, { "op": "add", "path": "/a/b/c", "value": "foo"}, { "op": "replace", "path": "/a/b/c", "value": 42 } ]

Slide 30

Slide 30 text

Nested resources are troublesome

Slide 31

Slide 31 text

Bet on “flat” APIs

Slide 32

Slide 32 text

Perceived speed

Slide 33

Slide 33 text

Pessimist vs optimist clients

Slide 34

Slide 34 text

Be pessimist : • Hard to rollback • Hard to predict the response

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Be optimist otherwise

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Asynchronous operations

Slide 39

Slide 39 text

Respond with 202 and one token so the client can poll

Slide 40

Slide 40 text

Offline and Caching strategies

Slide 41

Slide 41 text

Avoid it if possible

Slide 42

Slide 42 text

What if I have to?

Slide 43

Slide 43 text

Expose your API’s cache

Slide 44

Slide 44 text

Store the data and the cache’s timestamp. Next time request only changes and merge them.

Slide 45

Slide 45 text

Final thoughts

Slide 46

Slide 46 text

Build an API for the clients

Slide 47

Slide 47 text

REST allows server and client implementors work more efficiently

Slide 48

Slide 48 text

Explore new specs and trends but “don’t drink too much kool-aid"

Slide 49

Slide 49 text

Thanks for listening. ! We are hiring!