Core Data Flow
This page follows one send() through the client: from the request, through the dispatcher and the adapter, to the
cache and the components that read it. Read it before writing an adapter, a plugin or your own framework bindings.
The steps
- Create.
client.createRequest()builds an immutable request. ItscacheKey,queryKeyandabortKeyare derived from the method, endpoint and query params. - Dispatch.
send()adds it to the queue of itsqueryKeyinfetchDispatcher(GET, QUERY) orsubmitDispatcher. The dispatcher deduplicates, cancels or queues it, and holds it while the AppManager reports the app offline. - Intercept.
onRequest,onAuth(whenauthis on) and the request mapper change the request. - Send. The adapter sends it and reports start, upload, download and the response. Each step is an event on the RequestManager.
- Respond.
onResponse, thenonSuccessoronErrorchange the response. A failed attempt may be retried. - Store. A successful response is written to the cache under
cacheKey. The cache emits it to every reader of that key, andsend()resolves.
exec() skips steps 2 and 6: it runs the interceptors and the adapter only.
How the cache holds responses
Each cacheKey is one entry. Requests with the same method, filled endpoint and query params share it.
When an entry changes, by a response, cache.update, invalidate or an optimistic update, the cache emits an event for
that key. Every mounted reader of the key, such as useFetch, re-renders or refetches.
Next steps
Request lifecycle
Every lifecycle callback of a request, in React.
Plugin
Hook into every step of this flow.
Custom adapter
Write the adapter step for your own transport.