Upgrade to Pro — share decks privately, control downloads, hide ads and more …

REST clients

REST clients

On this presentation I talk about the evolution of web clients and how API's and REST shaped a new generation of web and mobile applications.

The second half I share some patterns that we discovered while building the web client for Redbooth.

masylum

May 29, 2014
Tweet

More Decks by masylum

Other Decks in Programming

Transcript

  1. Resource List of resources List of resources Client Server Robert

    (3) /cats /dogs grumpy.gif lolcat.png Tuesday, May 27, 14
  2. GET /users GET /users/1 POST /users PUT /users/1 Fetch list

    of resources Fetch a resource Create a resource Update a resource Destroy a resource DELETE /users/1 REST in a nutshell Tuesday, May 27, 14
  3. Example: POST /pictures Creates a picture Increases user “karma” GET

    /users/1 Gets user resource with the new “karma” score Side effect! (›°□°ʣ›ớ ᵲᴸᵲ Tuesday, May 27, 14
  4. Example: {...name:‘Bob’, karma:3} Client A Robert (3) PUT /users/1 Client

    B {...name:‘Robert’, karma:4} PUT /users/1 Robert (3) Tuesday, May 27, 14
  5. Example: {name:‘Bob’} Client A Robert (3) PATCH /users/1 Client B

    {karma:4} PATCH /users/1 Robert (3) Tuesday, May 27, 14
  6. A folder resource { id: 1 , name: ‘cats’ ,

    pictures: [ {id: 1, name: ‘1.gif} ]} Tuesday, May 27, 14
  7. A list of folder resources [ {id: 1..., pictures: [...]}

    , {id: 2..., pictures: [...]} ] Tuesday, May 27, 14
  8. • You bring more state at once • Increased perceived

    performance • Less requests to the server Pros Tuesday, May 27, 14
  9. • Worse “cacheability” • Inefficient, you may not need all

    that state • Too much state transfer: Side effects everywhere! Cons Tuesday, May 27, 14
  10. • Increased perceived performance • Clients can approximate a slow

    API operation • Narrows down the “eventual consistency” gap Pros Tuesday, May 27, 14
  11. • Error handling may be difficult • Reverting to previous

    state can be weird • Duplicated code in the server and the clients Cons Tuesday, May 27, 14
  12. Having the same language in both the client and the

    server can help. Tuesday, May 27, 14
  13. The API returns a token that you can poll to

    determine the status of the operation Tuesday, May 27, 14
  14. Long-lived resources can be stored on the client and then

    only sync differences Tuesday, May 27, 14
  15. API’s are like databases. We need a better way to

    interact with them Tuesday, May 27, 14