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
250
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
410
Building modern web applications. Single Responsibility Principle applied
mostr
4
150
You don't need Rails
mostr
3
170
Backendless frontend development
mostr
2
290
Code review, do you speak it?
mostr
0
450
Things you probably should know about JavaScript that you may not have been told before
mostr
6
630
Other Decks in Programming
See All in Programming
C# 大統一理論推進委員会 会員のための Unity Package Manager プロジェクト構成案
monry
PRO
0
580
Migrating to Signals: A Practical Workshop
manfredsteyer
PRO
0
280
導入から5年が経って見えた Datadog APM 運用の課題
bgpat
2
540
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
4
1.1k
自動テスト実行結果の目的を整理する / Organizing objectives of automated test results
twada
PRO
10
2.1k
プロンプトエンジニアリング入門
tomokusaba
2
990
PHPでOfficeファイルを取り扱う! PHP Officeライブラリを プロダクトに組み込んだ話
hirobe1999
0
840
9年開発を牽引して見えてきた、共通化すべきものと個別でつくるもの ~プログラム言語~
shinout
1
250
Honoとhtmx
yusukebe
6
1.2k
Compiling Python to WebAssembly with py2wasm
syrusakbary
0
140
生成 AI の中身を覗いてみよう〜基礎から医療現場での応用まで〜
soh9834
2
770
孤独のCTOグルメという やや奇抜な企画をやった目的と効果
shoheimitani
3
1k
Featured
See All Featured
What's new in Ruby 2.0
geeforr
335
31k
Mobile First: as difficult as doing things right
swwweet
215
8.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
23
1.9k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.8k
Unsuck your backbone
ammeep
661
56k
Designing the Hi-DPI Web
ddemaree
275
33k
Debugging Ruby Performance
tmm1
68
11k
Web Components: a chance to create the future
zenorocha
304
41k
The Invisible Side of Design
smashingmag
293
49k
Infographics Made Easy
chrislema
237
18k
Fireside Chat
paigeccino
19
2.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
15
6.3k
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