FetchHttpClient
Fetch-based implementation of the Effect HTTP client service.
This module provides an HttpClient layer that executes requests through a Web Fetch API implementation. It is the transport to use in browsers, edge runtimes, and Node.js environments where globalThis.fetch is available, or anywhere a compatible fetch function can be supplied.
Layers
Services
Context reference for the fetch implementation used by the fetch-based HTTP client.
Details
Defaults to globalThis.fetch.
Signature
declare const Fetch: Reference<(input: URL | RequestInfo, init?: RequestInit) => Promise<Response>>;RequestInit
Service that contains default fetch options for the fetch-based HTTP client.
When to use
Use to provide default credentials, cache, redirect, integrity, or other fetch options for outgoing HTTP requests.
Details
Request-specific method, headers, body, and abort signal are supplied by the client when a request is executed.
Signature
declare class RequestInit extends Shape<
"effect/http/FetchHttpClient/RequestInit",
RequestInit,
this
> {
constructor(_: never);
}
Layer that provides an
HttpClientimplementation backed by the configuredFetchfunction.When to use
Use when an Effect program should execute
HttpClientrequests through the platformfetchimplementation, especially in browser, edge, or Node.js runtimes withglobalThis.fetch.Details
The layer uses the current
Fetchreference and optionalRequestInitservice for each request. Request-specific method, headers, body, and abort signal are supplied by the client and override matchingRequestInitfields.Gotchas
Fetch behavior comes from the runtime's implementation, so CORS, cookies, redirects, abort handling, and streaming support can vary by platform. Stream request bodies are sent as Web streams with
duplex: "half", and anycontent-lengthheader is removed before callingfetch.See
Fetchfor supplying the fetch implementation used by this layerRequestInitfor defaultRequestInitoptions applied before request-specific fields