Coming from axios or ky
Map what you know from axios or ky to Effetch.
If you've used axios or ky, most of what you know has a counterpart in Effetch. The following table maps what you know from axios and ky to Effetch:
| axios or ky | Effetch |
|---|---|
axios.create, ky.create | Fetch.Service, or Fetch.make in a script |
ky.extend, a client per API version | A second Fetch.Service from { ...Api.config, baseUrl } (see Derive a client) |
baseURL, prefixUrl | baseUrl, a string or an Effect such as a Config |
params, searchParams | query, a plain object, or typed by an endpoint's query schema |
Interceptors, hooks.beforeRequest and hooks.afterResponse | A plugin's onRequest and onResponse |
hooks.beforeError | Effect.mapError on the call. A plugin's onError sees errors but can't change them |
retry, timeout | The retry and timeout plugins, which a call can turn off or adjust |
ky's totalTimeout | retry({ budget }), or Effect.timeout around a call |
AbortController, signal | Interruption: Fiber.interrupt, Effect.race, Effect.timeout. An interrupted call aborts its request |
validateStatus, throwHttpErrors: false | Effect.catchTag("HttpError", …), statusErrors, or Fetch.catchStatus and Fetch.optional |
error.response.data, ky's HTTPError body | HttpError.body, decoded with defaultError or the call's error schema |
ky.get(url).json<T>(), axios.get<T>(url) | api.get(path, { output: Schema }): the body is checked, not cast |
responseType: "text" or "arraybuffer" | output: Fetch.text() or Fetch.bytes() (see Read text or bytes) |
| Reading the status and headers with the data | responseMode: "decoded-and-response" (see Read the body and the response) |
responseType: "stream", onDownloadProgress for events | api.sse and api.ndjson |
A FormData body built by hand | input: Fetch.multipart(schema), a typed body sent as a form (see Upload files) |
The fetch option or an adapter in tests | FetchTest, or any HttpClient layer |