Skip to main content
Version: 0.1.2

Function: createAxiosFetchAdapter()

Imported from @react-logic/utils

createAxiosFetchAdapter(axios): FetchAdapter

Wrap an axios instance as a FetchAdapter. The instance you pass in is the one that will be used — install interceptors, base URLs, auth headers on it before passing.

The adapter forces axios into raw-text mode (responseType: 'text', transformResponse: identity) so the lazy json() / text() contract on FetchResponse matches the native fetch behaviour. JSON parsing happens in parse (or its default), not in the adapter.

validateStatus is set to null so axios doesn't throw on non-2xx — we want to surface the FetchResponse.ok = false path the same way fetch does. fetchState's default parse will then return a non-ok response, which the user can branch on in their own parse.

Parameters

axios

AxiosLikeClient

Your axios instance (e.g. axios.create({...}) or the default singleton).

Returns

FetchAdapter

A FetchAdapter ready to pass to setFetchStateAdapter or to the per-call fetcher config.