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

REST API edge cases

REST API edge cases

If you're lucky you can use so-called REST APIs in your daily work. Except, some of the largest (social) APIs make mistakes against the basic rules of REST. If you happen to be in the process of designing a REST API, you better refresh your knowledge on those REST principles. This talk will explain some quick REST API principles with lots of real-life examples, followed by some edge case designs including soft-deletes and "likes" as sub resources.

Presented at Laravel Brussels meetup in Antwerp.

Hannes Van De Vreken

October 29, 2014
Tweet

More Decks by Hannes Van De Vreken

Other Decks in Programming

Transcript

  1. REST BASICS - SOAP <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/…" soap:encodingStyle="http://www.w3.org/2001/…"> <soap:Body

    xmlns:m="http://www.example.org/stock"> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
  2. REST BASICS - HTTP METHODS - UPDATE PUT /users/driesvints HTTP/1.1

    Host: api.github.com { "login": "driesvints", "id": 594614, "avatar_url": "https://avatars.gith…", "email": "[email protected]", …
  3. REST BASICS - HTTP HEADERS - RATE LIMIT - GH

    HTTP/1.1 403 Forbidden X-RateLimit-Limit: 60 X-RateLimit-Remaining: 0 X-RateLimit-Reset: 1377013266
  4. REST BASICS - HTTP HEADERS - RATE LIMIT HTTP/1.1 429

    Too Many Requests X-RateLimit-Limit: 60 X-RateLimit-Remaining: 0 X-RateLimit-Reset: 1377013266
  5. CASE STUDY - GITHUB - STARRED? GET /user/starred/:owner/:repo HTTP/1.1 Host:

    api.github.com HTTP/1.1 204 No Content HTTP/1.1 404 Not found
  6. CASE STUDY - INSTAGRAM - LIKED? GET /v1/media/4b292…/likes HTTP/1.1 Host:

    api.instagram.com { "data": [ { "username": "gilbert_west", "id": "586708382", …
  7. HOW IT’S DONE - LIKES - LIKED? GET /notes/{id} HTTP/1.1

    Host: example.org { "liked": true, …
  8. HOW IT’S DONE - LIKES - PEOPLE WHO LIKED GET

    /notes/{id}/likes HTTP/1.1 Host: example.org
  9. • http:/ /wikipedia.org/wiki/SOAP • http:/ /meetup.com/mongodb-belgium • http:/ /mwl.be •

    http:/ /shop.oreilly.com/product/0636920028468.do • https:/ /leanpub.com/build-apis-you-wont-hate • https:/ /dev.twitter.com • http:/ /instagram.com/developer • https:/ /developer.github.com • https:/ /developer.foursquare.com REFERENCES