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
Data Loading Patterns with JSON API
Search
Balint Erdi
March 28, 2017
Technology
5
1.4k
Data Loading Patterns with JSON API
The talk I gave at EmberConf 2017, on 03/28/2017
Balint Erdi
March 28, 2017
Tweet
Share
More Decks by Balint Erdi
See All by Balint Erdi
Why you should consider Ember.js for your next project
balint
4
310
Data Loading Patterns in Ember
balint
1
210
Auth* in Ember apps with Torii
balint
1
300
(Somewhat) Complex Component Design – Ember.BP, 2015/02/11
balint
1
92
Complex Component Design in Ember
balint
0
380
Don't call me back - How Ember uses promises and how you can, too
balint
5
11k
Acceptance testing in Ember.js
balint
1
520
Unit testing in Ember.js
balint
0
84
Introduction to ember-data
balint
0
170
Other Decks in Technology
See All in Technology
初海外がre:Inventだった人間の感じたこと
tommy0124
1
200
新米エンジニアをTech Leadに任命する ー 成長を支える挑戦的な人と組織のマネジメント
naopr
1
370
Pythonで構築する全国市町村ナレッジグラフ: GraphRAGを用いた意味的地域検索への応用
negi111111
8
2.9k
決済システムの信頼性を支える技術と運用の実践
ykagano
0
260
Beyond Prompts: Building Intelligent Applications with Genkit and the Model Context Protocol
peterfriese
0
110
LLM APIを2年間本番運用して苦労した話
ivry_presentationmaterials
14
10k
Playwrightで始めるUI自動テスト入門
devops_vtj
0
220
AWS IAM Identity Centerによる権限設定をグラフ構造で可視化+グラフRAGへの挑戦
ykimi
2
460
DMARCは導入したんだけど・・・現場のつぶやき 〜 BIMI?何それ美味しいの?
hirachan
1
170
Zabbix Conference Japan 2025 ダッシュボードコンテストLT
katayamatg
0
130
Data & AIの未来とLakeHouse
ishikawa_satoru
0
600
こんな時代だからこそ! 想定しておきたいアクセスキー漏洩後のムーブ
takuyay0ne
3
360
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
246
12k
Docker and Python
trallard
46
3.6k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Balancing Empowerment & Direction
lara
5
720
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Practical Orchestrator
shlominoach
190
11k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
10
920
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
2.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8k
Transcript
Data Loading Patterns EmberConf 2017, Portland 03/28/2017
Data Loading Patterns with JSON API EmberConf 2017, Portland 03/28/2017
This talk is going to be … • A series
of prevalent use cases • Rich in code examples • Packed with actionable advice
Why JSON API?
What kind of API? • Backend dev: “What kind of
API are we going to use?” • Me: “JSON API” • We: “Let’s start working then”
CoC for APIs
Covering The Basics
Covering the basics (ED) • store.findRecord(‘band’, 1) • if the
record is in the store => returns it, and re-fetches it in the background • if the record is not in the store => returns a promise
Covering the basics (ED) • store.findAll(‘band’) • if >= 1
record in the store => returns them and triggers a refetch in the bg. • if there is no record in the store => returns a promise to fetch all of them
Covering the basics (ED) • store.peekRecord(‘band’, 1) • never triggers
a reload • returns the record if it’s in the store • returns null if it’s not
Covering the basics (ED) • store.peekAll(‘band’) • never triggers a
reload • returns the records already in the store
Covering the basics (ED) • shouldBackgroundReloadRecord • shouldBackgroundReloadAll • configurable
on the adapter
Covering the basics (Ember) • The model hooks are resolved
top-down • A child route is not entered before the hooks are run for its parent
Covering the basics (Ember) • Returning a promise in the
model hook “blocks” rendering the page • `findRecord`, `findAll`, `query` all return promises
The app
application bands bands.band.songs bands.band
Balint Erdi @baaz balinterdi.com Ember.js consultant
Case Studies
Fetching Relationship Data
Lazy Fetching
None
None
Pros & cons • Simple, works out of the box
• On-demand data fetching • Might trigger N requests • Disturbing flicker
Pre-loading the relationship
None
None
Move relationship data fetching to the route’s model hook if
you want to block rendering
Pros & cons • Better UX than the lazy fetching
scenario • Might still trigger N requests • RSVP.hash in the model hook is considered an anti-pattern
Side-loading
“An endpoint MAY also support an include request parameter to
allow the client to customize which related resources should be returned.”
None
None
None
None
Why is there a flicker? Shouldn’t the songs be side-loaded
and only then the page rendered?
None
None
None
Pros & cons • We leverage JSON:API • Explicit control
over fetching relationship data • Delays the rendering of the band template
Honorable mention: References API (ED 2.5)
Data loading strategy should be part of the design process
Searching on the Backend
“The filter query parameter is reserved for filtering data. Servers
and clients SHOULD use this key for filtering operations.”
None
None
Does a global search
None
None
Use a JSON API filter and query the relationship
Sorting
“An endpoint MAY support requests to sort the primary data
with a sort query parameter. The value for sort MUST represent sort fields.”
“The sort order for each sort field MUST be ascending
unless it is prefixed with a minus (U+002D HYPHEN-MINUS, “-“), in which case it MUST be descending.”
None
None
None
Use the JSON API `sort` parameter without transform
Pagination
“A server MAY choose to limit the number of resources
returned in a response to a subset (“page”) of the whole set available.”
“Note: JSON API is agnostic about the pagination strategy used
by a server. (…) The page query parameter can be used as a basis for any of these strategies.”
“Where specified, a meta member can be used to include
non-standard meta- information. The value of each meta member MUST be an object (a “meta object”).”
None
None
None
None
Use JSON API’s `page` parameters and pagination meta data
Indicating ongoing background record fetching
None
None
None
None
None
Eager return
None
None
Deconstruct the background data fetching process to have more control
over the loading process
Use ember-concurrency
None
No manual loading flag setting, run loop scheduling and reload
option setting
https://balinterdi.com/ emberconf
None
References • Rock and Roll with Ember book • {json:api}
specification • JSONAPI::Resources docs site • ember-concurrency or How I Learned to Stop Worrying and Love the Task on LinkedIn Enginnering • Lessons learned from four years with Ember by Ryan Toronto