Overview
fetchAction (and the method helpers) create an asyncAction whose body calls Mates Fetch. You get the full reactive state machine — data, isLoading, error, status — plus cache / startPolling from the same options object.
Config fixes host, url, method, headers, and default body/params. Call-time args are a plain params object: keys matching :tokens in the URL fill path segments; the rest become query-string params.
Module-level helpers (getAction, …) use the shared fetchClient. Prefer new FetchClient({ host }) + api.getAction(…) when you need a shared base URL or interceptors.
fetchAction vs asyncAction vs asyncAtom
|
API
|
Role
|
Prefer when
|
|---|---|---|
fetchAction / getAction…
| HTTP + asyncAction | Declarative URL/method config; call with params. Built on Fetch. |
asyncAction
| Any async fn |
Custom Promise work, non-HTTP, or when you wrap Post/Fetch yourself.
|
asyncAtom
| Resource atom | Keyed auto-fetch from atom deps — read like an atom. See asyncAtom. |
getAction — real GET with :id params
getAction fills :id from call-time params and hits jsonplaceholder. You get data / isLoading / error / status, plus cancel() and interceptAfter.
getAction.cache() vs a plain call
cache({ id }) skips the network on a hit — loadedAt from interceptAfter stays the same. A plain call() always fetches. clearCache() drops the LRU.
postAction — config body, JSON response
postAction sends the config body. Call-time params would go to the URL, not the JSON body — so the payload lives on the factory config.