NodeHttpClient
Node.js implementations of the Effect HttpClient.
This module supplies Node runtime backends for the platform-independent Effect HTTP client API. It re-exports the fetch-based Fetch, RequestInit, and layerFetch APIs, defines an Undici-backed client with dispatcher services and request options, and defines a lower-level node:http / node:https client with scoped HTTP agent layers.
Constructors
makeNodeHttp
Signature
declare const makeNodeHttp: Effect<HttpClient, never, HttpAgent>;makeUndici
Creates an HttpClient that sends requests through the current Undici Dispatcher, converts Effect HTTP bodies to Undici bodies, and maps transport and decode failures to HttpClientError.
Signature
declare const makeUndici: Effect<HttpClient, never, Dispatcher>;Layers
dispatcherLayerGlobal
Provides the Dispatcher service from Undici's process-global dispatcher, without creating or owning a new agent.
Signature
declare const dispatcherLayerGlobal: Layer.Layer<Dispatcher>;layerAgent
Provides the HttpAgent service using default scoped Node http and https agents.
Signature
declare const layerAgent: Layer.Layer<HttpAgent>;layerAgentOptions
Provides the HttpAgent service using scoped Node http and https agents configured with the supplied options.
Signature
declare const layerAgentOptions: (options?: Https.AgentOptions) => Layer.Layer<HttpAgent>;layerDispatcher
Provides the Dispatcher service using a scoped Undici Agent.
Signature
declare const layerDispatcher: Layer.Layer<Dispatcher>;layerFetch
Layer that provides an HttpClient implementation backed by the configured Fetch function.
When to use
Use when an Effect program should execute HttpClient requests through the platform fetch implementation, especially in browser, edge, or Node.js runtimes with globalThis.fetch.
Details
The layer uses the current Fetch reference and optional RequestInit service for each request. Request-specific method, headers, body, and abort signal are supplied by the client and override matching RequestInit fields.
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 any content-length header is removed before calling fetch.
See
Fetchfor supplying the fetch implementation used by this layerRequestInitfor defaultRequestInitoptions applied before request-specific fields
Signature
declare const layerFetch: Layer.Layer<HttpClient.HttpClient>;layerNodeHttp
Provides a node:http-backed HttpClient together with default scoped Node http and https agents.
Signature
declare const layerNodeHttp: Layer.Layer<Client.HttpClient>;layerNodeHttpNoAgent
Provides a node:http-backed HttpClient using the current HttpAgent service.
Signature
declare const layerNodeHttpNoAgent: Layer.Layer<Client.HttpClient, never, HttpAgent>;layerUndici
Provides an Undici-backed HttpClient together with a scoped default Undici Agent dispatcher.
Signature
declare const layerUndici: Layer.Layer<Client.HttpClient>;layerUndiciNoDispatcher
Provides an Undici-backed HttpClient using the current Dispatcher service.
Signature
declare const layerUndiciNoDispatcher: Layer.Layer<Client.HttpClient, never, Dispatcher>;Resource Management
Acquires Node http and https agents with the supplied options and destroys both agents when the enclosing scope is finalized.
Signature
declare function makeAgent(options?: any): Effect<
{
readonly http: Agent;
readonly https: Agent;
},
never,
Scope
>;makeDispatcher
Acquires a new Undici Agent dispatcher and destroys it when the enclosing scope is finalized.
Signature
declare const makeDispatcher: Effect.Effect<Undici.Dispatcher, never, Scope.Scope>;Services
Dispatcher
Service tag for the Undici Dispatcher used by the Undici-backed HTTP client.
Signature
declare class Dispatcher extends Shape<
"@effect/platform-node/NodeHttpClient/Dispatcher",
Dispatcher,
this
> {
constructor(_: never);
}Fetch
Context reference for the fetch implementation used by the fetch-based HTTP client.
Details
Defaults to globalThis.fetch.
Signature
declare const Fetch: Context.Reference<typeof globalThis.fetch>;Service tag for the paired Node http and https agents used by the node:http-backed HTTP client.
Signature
declare class HttpAgent extends Shape<
"@effect/platform-node/NodeHttpClient/HttpAgent",
{
readonly http: Agent;
readonly https: Agent;
},
this
> {
constructor(_: never);
}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 RequestInit_base {
constructor(_: never);
}UndiciOptions
Fiber reference containing default Undici request options applied to requests sent by makeUndici.
Signature
declare const UndiciOptions: Reference<RequestOptions>;
Creates an
HttpClientbacked by Nodehttpandhttps, using the currentHttpAgent, streaming request bodies, and wrapping Node responses asHttpClientResponsevalues.