Slide 1

Slide 1 text

{json:api} A specification for building APIs in JSON

Slide 2

Slide 2 text

{json:api} A specification for building APIs in JSON duh

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

{json:api}

Slide 6

Slide 6 text

{json:api}

Slide 7

Slide 7 text

{"json":"api"}

Slide 8

Slide 8 text

Why?

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

» Minimize requests & data between clients & servers » Consistency, popular among consultancies » Always backwards compatible » Stable 1.0, not dead

Slide 11

Slide 11 text

No really

Slide 12

Slide 12 text

History

Slide 13

Slide 13 text

!+"+#$+%=

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Spec

Slide 16

Slide 16 text

» data: the document’s “primary data” » errors: an array of error objects » meta: a meta object that contains non-standard meta- information.

Slide 17

Slide 17 text

Data

Slide 18

Slide 18 text

{ "data": { "type": "articles", "id": "1", "attributes": { "title": "Rails is Omakase" }, "relationships": { }, "links": { "self": "http://example.com/articles/1" }, } }

Slide 19

Slide 19 text

Relationships

Slide 20

Slide 20 text

{ "relationships": { "author": { "links": { "self": "/articles/1/relationships/author", "related": "/articles/1/author" }, "data": { "type": "people", "id": "9" } } } }

Slide 21

Slide 21 text

Meta

Slide 22

Slide 22 text

{ "meta": { "count": "42", "copyright": "Copyright 2015 Example Corp.", "authors": [ "Yehuda Katz", "Steve Klabnik", "Dan Gebhardt", "Tyler Kellen" ] } }

Slide 23

Slide 23 text

Errors

Slide 24

Slide 24 text

{ "errors": [ "id": "UUID", "status": "418", "code": "42", "title": "You're a teapot", "detail": "The object is not short nor stout", "links": { "about": "https://httpstatuses.com/418" }, "meta": { "email": "[email protected]" } ] }

Slide 25

Slide 25 text

GET /articles Accept: application/vnd.api+json GET /articles/1 Accept: application/vnd.api+json GET /articles/1/author Accept: application/vnd.api+json

Slide 26

Slide 26 text

#Request comments with an article GET /articles/1?include=comments Accept: application/vnd.api+json #Request comments as well as the author of each of those comments GET /articles/1?include=comments.author Accept: application/vnd.api+json

Slide 27

Slide 27 text

GET /articles?include=comments,author &fields[people]=first-name,last-name &sort=-date » fetch all articles with their associated comments and authors » Only be return the first and last names » Sorted by date, most recent first

Slide 28

Slide 28 text

POST /photos { "data": { "type": "photos", "attributes": { "title": "Ember Hamster", "src": "http://example.com/images/productivity.png" }, "relationships": { "photographer": { "data": { "type": "people", "id": "9" } } } } }

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content