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

JSON API - standards please

JSON API - standards please

Slides from my Meet.JS talk on JSON API standards (JSend and JSON API specifications)

Michal Ostruszka

January 14, 2014
Tweet

More Decks by Michal Ostruszka

Other Decks in Programming

Transcript

  1. “JSend is a specification that lays down some rules for

    how JSON responses from web servers should be formatted” JSend
  2. JSend - failure { “status”: “fail”, “data”: { “title”: “Title

    is required” } } Used for invalid data responses required: status = “fail”, data
  3. JSend - error { “status”: “error”, “message”: “Server goes bananas”

    } Used for server errors required: status = “error”, message optional: code, data
  4. “If you've ever argued with your team about the way

    your JSON responses should be formatted, JSON API is your anti-bikeshedding weapon.” JSON API
  5. JSON API - Simple { “posts”: [{ “id”: 1, “title”:

    “Hello world” }] } always as list, even for 1 item item MUST contain “id”
  6. JSON API - Relationships { “posts”: [{ “id”: 1, “title”:

    “Hello world”, “links”: { “author”: “9” “comments”: [“1”,”2”,”3”] } }] } Client needs to know how to build author url
  7. URL Style { “posts”: [{ “id”: 1, “title”: “Hello world”,

    “links”: { “author”: “http://example.com/author/2” } }] } client can blindly follow URLs
  8. Once JSON API is stable, it will always be backwards

    compatible using a never remove, only add strategy Changes?