API reference
createFetcher
The transport, and how to replace it.
const fetcher = createFetcher({ baseUrl?, defaultHeaders?, serializeParams? });baseUrlstringdefaults to ''
- A fallback origin, used only when the call context supplies none.
- An endpoint’s own
baseUrlalways wins, so setting both does not double the origin.
defaultHeadersRecord<string, string>
- Merged under the headers the pipeline resolved, so pipeline headers win.
serializeParams(params) => stringdefaults to defaultSerializeParams
- Controls query-string encoding. The default encodes arrays as repeated keys and nested objects as JSON.
- Replace it if your backend expects bracket or dot notation.
Writing your own
A fetcher is a function. Implement it to route through your own client, to mock in tests, or to add transport-level retries.
const fetcher: EndpointFetcher = async (request, headers, ctx) => {
const res = await myClient(ctx.method, `${ctx.baseUrl ?? ''}${ctx.path}`, {
body: request,
headers,
signal: ctx.signal,
});
return {
data: res.body,
status: res.status,
statusText: res.statusText,
ok: res.status < 400,
headers: res.headers, // optional, lower-cased
};
};