Skip to Content

Coming from axios or ky

Map what you know from axios or ky to Effetch, and see what has no counterpart.

If you've used axios or ky, you already know most of what Effetch does. The names are different, and a few things move: a hook becomes a plugin, a cast becomes a schema, and an abort signal becomes interruption. This page maps each option and habit to its counterpart in Effetch, and lists what has none.

Clients and requests

The following table maps how you create a client and build a request:

axios or kyEffetch
axios.create, ky.createFetch.Service, or Fetch.make in a script
ky.extend, a client per API versionA second Fetch.Service from { ...Api.config, baseUrl } (see Derive a client)
axios's baseURL; ky's baseUrl or prefix (prefixUrl before ky 2)baseUrl, a string or an Effect such as a Config. It's joined to the path as a string, as ky's prefix is
headersheaders, on the client or on one call
params, searchParamsquery, a plain object, or typed by an endpoint's query schema
axios's data, ky's jsonbody, which an input schema can type and check (see Send a body)
A FormData body built by handinput: Fetch.multipart(schema), a typed body sent as a form (see Upload files)
axios's withCredentials, ky's credentialscredentials: "include" in FetchHttpClient.RequestInit (see Send cookies)

Responses

The following table maps how you read what comes back:

axios or kyEffetch
ky.get(url).json<T>(), axios.get<T>(url)api.get(path, { output: Schema }). The body is checked against the schema, not cast
responseType: "text" or "arraybuffer"output: Fetch.text() or Fetch.bytes() (see Read text or bytes)
Reading the status and headers with the dataresponseMode: "decoded-and-response" (see Read the body and the response)
responseType: "stream", onDownloadProgress for eventsapi.sse and api.ndjson, which give the events or lines as a Stream
responseType: "stream" for raw bytesA call without output. It succeeds with the HttpClientResponse, whose stream reads the body as it arrives (see Skip decoding)

Errors

The following table maps how you handle a failed call:

axios or kyEffetch
validateStatus, throwHttpErrors: falseEffect.catchTag("HttpError", …), statusErrors, or Fetch.catchStatus and Fetch.optional
error.response.data, ky's HTTPError bodyHttpError.body, decoded with defaultError or the call's error schema (see Read the error body)
hooks.beforeErrorEffect.mapError on the call. A plugin's onError receives errors, but can't change them

Hooks, retries, cancellation and tests

The following table maps what runs around every request:

axios or kyEffetch
Interceptors, hooks.beforeRequest and hooks.afterResponseA plugin's onRequest and onResponse
An interceptor that adds a tokenThe bearer plugin, which can also refresh the token (see Refresh a token)
retry, timeoutThe retry and timeout plugins, which a call can turn off or adjust
ky's totalTimeoutretry({ budget }), or Effect.timeout around a call
AbortController, signalInterruption, with Fiber.interrupt, Effect.race or Effect.timeout. An interrupted call aborts its request
transformRequest, transformResponse, ky's parseJson and stringifyJsonAn input or output schema, which encodes or decodes the body, such as a date string into a Date. For anything else, a plugin's onRequest or onResponse can return a changed request or response

In tests, where you'd pass ky a fetch option or give axios an adapter, provide FetchTest or any other HttpClient layer instead.

What has no counterpart

Some features of axios and ky have no counterpart in Effetch:

  • Upload and download progress. Effetch has no onUploadProgress or onDownloadProgress, and Effect's HttpClient doesn't report progress either.
  • paramsSerializer. The query format is fixed: an array repeats its key, as in tags=a&tags=b. For another format, build the value yourself, such as tags: tags.join(",").

What's next

On this page