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 - standards please
Search
Michal Ostruszka
January 14, 2014
Programming
2
260
JSON API - standards please
Slides from my Meet.JS talk on JSON API standards (JSend and JSON API specifications)
Michal Ostruszka
January 14, 2014
Tweet
Share
More Decks by Michal Ostruszka
See All by Michal Ostruszka
Building modern web applications. Single Responsibility Principle applied
mostr
2
430
Building modern web applications. Single Responsibility Principle applied
mostr
4
160
You don't need Rails
mostr
3
180
Backendless frontend development
mostr
2
310
Code review, do you speak it?
mostr
0
500
Things you probably should know about JavaScript that you may not have been told before
mostr
6
680
Other Decks in Programming
See All in Programming
テスターからテストエンジニアへ ~新米テストエンジニアが歩んだ9ヶ月振り返り~
non0113
2
220
おやつのお供はお決まりですか?@WWDC25 Recap -Japan-\(region).swift
shingangan
0
140
[SRE NEXT] 複雑なシステムにおけるUser Journey SLOの導入
yakenji
0
150
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
1.1k
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
200
Deep Dive into ~/.claude/projects
hiragram
14
14k
AIともっと楽するE2Eテスト
myohei
8
3k
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
280
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
500
RailsGirls IZUMO スポンサーLT
16bitidol
0
200
可変変数との向き合い方 $$変数名が踊り出す$$ / php conference Variable variables
gunji
0
180
PicoRuby on Rails
makicamel
2
140
Featured
See All Featured
Statistics for Hackers
jakevdp
799
220k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
47
9.6k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
990
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
How to Ace a Technical Interview
jacobian
278
23k
Building Applications with DynamoDB
mza
95
6.5k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
KATA
mclloyd
30
14k
Transcript
JSON API standards please Michał Ostruszka | @mostruszka | michalostruszka.pl
every app defines own “standard” Wild, wild west
{ “status”: “ok”, “response”: {...} }
{ “result”: “success”, “data”: [] }
{ “status”: 200 }
{ “result”: “error”, “msg”: “No such user” }
{ “status”: 404, “error”: “No such user” }
{ “status”: 404, “errors”: [ “No such user” ] }
and so on...
sometimes even within one app Inconsistency
Any standards?
“JSend is a specification that lays down some rules for
how JSON responses from web servers should be formatted” JSend
JSend - success { “status”: “success”, “data”: { “posts”: [...]
} } required: status, data
JSend - failure { “status”: “fail”, “data”: { “title”: “Title
is required” } } Used for invalid data responses required: status = “fail”, data
JSend - error { “status”: “error”, “message”: “Server goes bananas”
} Used for server errors required: status = “error”, message optional: code, data
simple easy to follow, “data” can contain anything That’s all
only 41 various interpretations not always flexible enough Wait, HTTP
codes?
“If you've ever argued with your team about the way
your JSON responses should be formatted, JSON API is your anti-bikeshedding weapon.” JSON API
defines data format, mime type registered application/vnd.api+json relations etc Bigger
spec
ID style URL style Flavors
JSON API - Simple { “posts”: [{ “id”: 1, “title”:
“Hello world” }] } always as list, even for 1 item item MUST contain “id”
JSON API - Relationships { “posts”: [{ “id”: 1, “title”:
“Hello world”, “links”: { “author”: “9” “comments”: [“1”,”2”,”3”] } }] } Client needs to know how to build author url
Embedded in “linked” field Save HTTP requests Compound docs
Same for simple resources URL Style
URL Style { “posts”: [{ “id”: 1, “title”: “Hello world”,
“links”: { “author”: “http://example.com/author/2” } }] } client can blindly follow URLs
GET /posts/1?include=comments GET /posts/1?include=comments.author Selective fetching
Defines how to send data POST, PUT, DELETE etc Resources
manipulation
No status in response body HTTP codes used to determine
status Relies on HTTP codes
Once JSON API is stable, it will always be backwards
compatible using a never remove, only add strategy Changes?
http://labs.omniti.com/labs/jsend http://jsonapi.org/ Where to find?
Possible adoption? Stick to standard for your project JSend looks
easier Final word
kthxbye