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

The JSON:API spec

The JSON:API spec

Introduction to the JSON:API spec

Marco Otte-Witte

September 20, 2017
Tweet

More Decks by Marco Otte-Witte

Other Decks in Programming

Transcript

  1. » curl https://api.github.com/repos/rails/rails HTTP/1.1 200 OK … { "id": 1,

    "name": "sinatra", … "owner": { "login": "rails", "id": 4223, … } }
  2. » curl -i https://api.travis-ci.org/repos/rails/rails HTTP/1.1 200 OK … { "repo":

    { "id": 82, "slug": "sinatra/sinatra", … "last_build_id": 23436881, … } }
  3. { "data": { "type": "articles", "id": "1", "attributes": { "title":

    "JSON API paints my bikeshed!" } } } HTTP/1.1 200 OK Content-Type: application/vnd.api+json
  4. GET /articles/1 { "data": { "type": "articles", "id": "1", "attributes":

    { "title": "JSON API paints my bikeshed!" } } }
  5. GET /articles { "data": [ { "type": "articles", "id": "1",

    "attributes": { "title": "JSON API paints my bikeshed!" } }, { "type": "articles", "id": "2", "attributes": { "title": "Rails is Omakase" } } ] }
  6. GET /articles/1 { "data": { "type": "articles", "id": "1", "attributes":

    { "title": "JSON API paints my bikeshed!" }, "relationships": { "author": { "data": { "type": "people", "id": "1" } } } } }
  7. GET /articles/1 { "data": { "type": "articles", "id": "1", "attributes":

    { "title": "JSON API paints my bikeshed!" }, "relationships": { "author": { "data": { "type": "people", "id": "1" } } } }, "included": [ { "type": "people", "id": "1", "attributes": { "name": "Dan Gebhard" } } ] }
  8. GET /articles/1 { "data": { "type": "articles", "id": "1", "attributes":

    { "title": "JSON API paints my bikeshed!" }, "relationships": { "author": { "links": { "self": "/articles/1/relationships/author", "related": "/articles/1/author" } } } } }
  9. HTTP/1.1 201 Created Location: http://example.com/articles/1 { "data": { "type": "articles",

    "id": "1", "attributes": { "title": "JSON API paints my bikeshed!" } } }
  10. PATCH /articles/1 { "data": { "type": "articles", "id": "1", "attributes":

    { "title": "json:api paints my bikeshed!" } } }
  11. { "data": { "type": "articles", "id": "1", "attributes": { "title":

    "JSON API paints my bikeshed!" } } } HTTP/1.1 200 OK Content-Type: application/vnd.api+json ETag: "686897696a7c876b7e"
  12. GET /articles?include=author { "data": [ { "type": "articles", "id": "1",

    "attributes": { "title": "JSON API paints my bikeshed!", "text": "…" }, "relationships": { "author": { "data": { "type": "people", "id": "2" } } } }, … ], "included": [ { "type": "people", "id": "2", "attributes": { "name": "Dan Gebhard", "bio": "…", "imageUrl": "…" } }, … ] }
  13. Q&A