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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Marco Otte-Witte
November 13, 2015
Technology
1
2k
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
240
Handling images on the web
marcoow
0
430
SSR, SPAs and PWAs
marcoow
0
360
Fast, Fast, Fast
marcoow
2
510
Feel the Glimmer - ParisJS
marcoow
1
540
Feel the Glimmer - MunichJS 11/17
marcoow
0
150
The JSON:API spec
marcoow
3
1.8k
Leveraging the complete Ember Toolbelt
marcoow
0
400
Feel the Glimmer
marcoow
1
250
Other Decks in Technology
See All in Technology
IaaS/SaaS管理における SREの実践 - SRE Kaigi 2026
bbqallstars
4
1.5k
新規事業における「一部だけどコア」な AI精度改善の優先順位づけ
zerebom
0
490
AI時代、1年目エンジニアの悩み
jin4
1
150
Tebiki Engineering Team Deck
tebiki
0
23k
Agile Leadership Summit Keynote 2026
m_seki
1
190
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
0
120
What happened to RubyGems and what can we learn?
mikemcquaid
0
220
外部キー制約の知っておいて欲しいこと - RDBMSを正しく使うために必要なこと / FOREIGN KEY Night
soudai
PRO
9
3.9k
ClickHouseはどのように大規模データを活用したAIエージェントを全社展開しているのか
mikimatsumoto
0
140
オープンウェイトのLLMリランカーを契約書で評価する / searchtechjp
sansan_randd
3
630
AIとともに歩む情報セキュリティ / Information Security with AI
kanny
4
3.2k
Oracle Cloud Observability and Management Platform - OCI 運用監視サービス概要 -
oracle4engineer
PRO
2
14k
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
53
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.6k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
720
Building the Perfect Custom Keyboard
takai
2
680
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
170
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
50
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
120
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
78
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