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.9k
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
120
Handling images on the web
marcoow
0
390
SSR, SPAs and PWAs
marcoow
0
350
Fast, Fast, Fast
marcoow
2
470
Feel the Glimmer - ParisJS
marcoow
1
490
Feel the Glimmer - MunichJS 11/17
marcoow
0
130
The JSON:API spec
marcoow
3
1.7k
Leveraging the complete Ember Toolbelt
marcoow
0
340
Feel the Glimmer
marcoow
1
230
Other Decks in Technology
See All in Technology
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
110
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
27
12k
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
170
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
260
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
AWS re:Invent 2024 ふりかえり
kongmingstrap
0
130
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
530
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.2k
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Thoughts on Productivity
jonyablonski
67
4.4k
For a Future-Friendly Web
brad_frost
175
9.4k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Designing for humans not robots
tammielis
250
25k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
It's Worth the Effort
3n
183
28k
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