Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
JSON API
Search
Marco Otte-Witte
November 13, 2015
Technology
1
1.8k
JSON API
Introduction to JSON API - a talk I gave at RubyDay 2015.
Marco Otte-Witte
November 13, 2015
Tweet
Share
More Decks by Marco Otte-Witte
See All by Marco Otte-Witte
Securing Technology Investments
marcoow
0
84
Handling images on the web
marcoow
0
390
SSR, SPAs and PWAs
marcoow
0
330
Fast, Fast, Fast
marcoow
2
420
Feel the Glimmer - ParisJS
marcoow
1
440
Feel the Glimmer - MunichJS 11/17
marcoow
0
120
The JSON:API spec
marcoow
3
1.6k
Leveraging the complete Ember Toolbelt
marcoow
0
240
Feel the Glimmer
marcoow
1
220
Other Decks in Technology
See All in Technology
プッシュ型子育てサービスを、先行プロジェクト実施自治体において開始します
govtechtokyo
0
220
匠MethodとRDRAとICONIXとDDDで実現する一気通貫オブジェクト指向開発
haru860
4
1.5k
エンジニアブランディングチームの KPI / KPI's of engineer branding team
chaspy
1
140
GraphQLに入門してみた
chiroruxx
2
100
Ask-LLM論文紹介: How to Train Data-Efficient LLMs
s_ota
0
110
生成AIサービスPanorama AIご説明資料
sdt
0
300
20240321_生成AI時代のDevOps
kzkmaeda
2
600
KTC_DBRE.pdf
_awache
0
290
10分でわかるfreeeのQA
freee
0
210
オブジェクト指向CSSが叶えたかったことと、CSSのいま / The aims of Object-oriented CSS and the current state of CSS usage
shinkufencer
11
3.1k
Getting started with controlling LEGO using Swift
hcrane
0
120
既存プロセスからの脱却と変化に適応するために必要なこと
cybozuinsideout
PRO
2
170
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
266
39k
Designing for Performance
lara
601
67k
Building a Scalable Design System with Sketch
lauravandoore
455
32k
GraphQLとの向き合い方2022年版
quramy
28
12k
No one is an island. Learnings from fostering a developers community.
thoeni
14
2k
Web development in the modern age
philhawksworth
201
10k
What's in a price? How to price your products and services
michaelherold
236
11k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
225
51k
How to train your dragon (web standard)
notwaldorf
71
5.1k
Principles of Awesome APIs and How to Build Them.
keavy
119
16k
The World Runs on Bad Software
bkeepers
PRO
60
6.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
257
12k
Transcript
None
Marco Otte-Witte @marcoow
http://simplabs.com @simplabs
None
http://jsonapi.org
A specification for building APIs in JSON
None
“ “ “ “
“ “ “ “
Why is this even needed?
https://twitter.com/thomasfuchs/status/604323589979049984
everybody is using RESTful JSON APIs already
…but they are all different
GET /repos/sinatra/sinatra { "id": 1, "name": "sinatra", … }
GET /repos/sinatra/sinatra { "repo": { "id": 82, "name": "sinatra/sinatra", …
} }
GET /1.1/users/show.json? screen_name=marcoow { "id": 1, "name": "marcoow", … }
GET /users/marcoow { "id": 1, "login": "marcoow", … }
GET /repos/simplabs/rails_api_auth { "id": 1, "name": "rails_api_auth", "owner": { "id":
1, "name": "simplabs", … } … }
GET /repos/:repo_id/branches/master { "branches": { { "id": 1, "repository_id": 891,
… } } }
https://www.broxap.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/i/bikeshed_bxmwmu2.jpg_1.jpg.jpg
JSON API is your anti bikeshedding weapon
some History
it started with a lengthy discussion between Yehuda Katz and
Steve Klabnik at RailsConf 2013
Yehuda wrote the first draft
1.0 released on May 29th 2015
None
the Goals
define a generic media type that works across a broad
set of use cases
make the format similar to existing server-side framework practices
having a human readable format that is also easy to
debug
ensuring ease of implementation both on the server as well
as on the client side
the Format
Media Type application/vnd.api+json http://www.iana.org/assignments/media-types/application/vnd.api+json
Resource Objects represent individual resources
GET /articles/1 { "data": { "type": "articles", "id": "1", "attributes":
{ "title": "JSON API paints my bikeshed!" } } }
GET /articles { "data": [ { "type": "articles", "id": "1",
"attributes": { "title": "JSON API paints my bikeshed!" } }, { "type": "articles", "id": "2", "attributes": { "title": "Rails is Omakase" } } ] }
GET /articles/1 { "data": { "type": "articles", "id": "1", "attributes":
{ "title": "JSON API paints my bikeshed!" }, "relationships": { "author": { "data": { "type": "people", "id": "1" } } } } }
Hypermedia is part of the spec but opt-in
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" } } } } }
Inclusion of related resources is a way of reducing requests
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" } }] }
CRUD works pretty much as you'd expect
GET /articles GET /articles/1 POST /articles PATCH /articles/1 DELETE /articles/1
POST /articles { "data": { "type": "articles", "attributes": { "title":
"JSON API paints my bikeshed!" } } }
HTTP/1.1 201 Created Location: http://example.com/articles/1 { "data": { "type": "articles",
"id": "1", "attributes": { "title": "JSON API paints my bikeshed!" } } }
PATCH /articles/1 { "data": { "type": "articles", "id": "1", "attributes":
{ "title": "json:api paints my bikeshed!" } } }
HTTP/1.1 204 No Content
DELETE /articles/1
HTTP/1.1 204 No Content
Advanced Features
Inclusion of related resources can also be requested by the
client
GET /articles/1?include=comments.author
Sparse field sets can be used to reduce the response
size
GET /articles? include=author&fields[articles]=title,body&fi elds[people]=name
Bulk Operations allow creating/updating/deleting multiple resources at once
POST /articles { "data": [{ "type": "articles", "attributes": { "title":
"JSON API paints my bikeshed!" } }, { "type": "articles", "attributes": { "title": "Rails is Omakase" } }] }
HTTP/1.1 201 Created { "data": [{ "type": "articles", "id": "1",
"attributes": { "title": "JSON API paints my bikeshed!" } },{ "type": "articles", "id": "2", "attributes": { "title": "Rails is Omakase" } }] }
Ruby Implementations
ActiveModelSerializers supports it in 0.10.0 https://github.com/rails-api/active_model_serializers
ROAR https://github.com/apotonick/roar
JSONAPI::Resources https://github.com/cerebris/jsonapi-resources
Client Libraries are available for many languages http://jsonapi.org/implementations/
None
♥
http://simplabs.com @simplabs