Overview
FetchClient holds a base FetchRequest (host, default headers, …) merged under every call, plus its own interceptor chain. Module helpers (Get, Post, …) wrap a shared default instance.
In apps — especially SSR — prefer useUtils().fetchClient and useUtils().interceptBefore / interceptAfter / interceptError. Those interceptors live on the request-scoped FetchUtils, not a process-global singleton.
Action factories (getAction, postAction, …) return asyncActions bound to the client — call with a params object for path/query substitution.
Client vs helpers
|
API
|
Scope
|
Prefer when
|
|---|---|---|
Get / Post / …
| Default singleton | Scripts & one-offs — see Fetch & HTTP. |
new FetchClient({ host })
| Module / service | Shared base URL + per-instance interceptors. |
useUtils().fetchClient
| App / SSR | Scoped interceptors isolated per MatesUtils. |
FetchClient with shared host
One client, two GETs against JSONPlaceholder. Path params via params: { id }.
useUtils().fetchClient + interceptBefore
Scoped client from renderApp’s MatesUtils. interceptBefore logs each URL before the request.