NodeHttpClient.ts
NodeHttpClient.ts overview
Section titled “NodeHttpClient.ts overview”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.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”Dispatcher
Section titled “Dispatcher”Dispatcher (class)
Section titled “Dispatcher (class)”Service tag for the Undici Dispatcher used by the Undici-backed HTTP
client.
Signature
declare class DispatcherSince v4.0.0
dispatcherLayerGlobal
Section titled “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, never, never>Since v4.0.0
layerDispatcher
Section titled “layerDispatcher”Provides the Dispatcher service using a scoped Undici Agent.
Signature
declare const layerDispatcher: Layer.Layer<Dispatcher, never, never>Since v4.0.0
makeDispatcher
Section titled “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>Since v4.0.0
HttpAgent
Section titled “HttpAgent”HttpAgent (class)
Section titled “HttpAgent (class)”Service tag for the paired Node http and https agents used by the
node:http-backed HTTP client.
Signature
declare class HttpAgentSince v4.0.0
layerAgent
Section titled “layerAgent”Provides the HttpAgent service using default scoped Node http and
https agents.
Signature
declare const layerAgent: Layer.Layer<HttpAgent, never, never>Since v4.0.0
layerAgentOptions
Section titled “layerAgentOptions”Provides the HttpAgent service using scoped Node http and https
agents configured with the supplied options.
Signature
declare const layerAgentOptions: (options?: Https.AgentOptions | undefined) => Layer.Layer<HttpAgent>Since v4.0.0
makeAgent
Section titled “makeAgent”Acquires Node http and https agents with the supplied options and
destroys both agents when the enclosing scope is finalized.
Signature
declare const makeAgent: (options?: Https.AgentOptions) => Effect.Effect<HttpAgent["Service"], never, Scope.Scope>Since v4.0.0
Undici
Section titled “Undici”UndiciOptions
Section titled “UndiciOptions”Fiber reference containing default Undici request options applied to requests
sent by makeUndici.
Signature
declare const UndiciOptions: Context.Reference<Partial<Undici.Dispatcher.RequestOptions<null>>>Since v4.0.0
layerUndici
Section titled “layerUndici”Provides an Undici-backed HttpClient together with a scoped default
Undici Agent dispatcher.
Signature
declare const layerUndici: Layer.Layer<Client.HttpClient, never, never>Since v4.0.0
layerUndiciNoDispatcher
Section titled “layerUndiciNoDispatcher”Provides an Undici-backed HttpClient using the current Dispatcher
service.
Signature
declare const layerUndiciNoDispatcher: Layer.Layer<Client.HttpClient, never, Dispatcher>Since v4.0.0
makeUndici
Section titled “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.Effect<Client.HttpClient, never, Dispatcher>Since v4.0.0
Provides a fetch-based HTTP client implementation for Node.js.
When to use
Use to access or override the fetch implementation used by the Node fetch-based HTTP client.
Signature
declare const Fetch: Context.Reference<{ (input: RequestInfo | URL, init?: RequestInit): Promise<Response> (input: string | URL | Request, init?: RequestInit): Promise<Response>}>Since v4.0.0
RequestInit
Section titled “RequestInit”Provides request initialization options accepted by the fetch-based HTTP client.
When to use
Use to provide default fetch request options for Node HTTP requests.
Signature
declare const RequestInit: typeof RequestInitSince v4.0.0
layerFetch
Section titled “layerFetch”Layer that provides the fetch-based HTTP client implementation.
Signature
declare const layerFetch: Layer.Layer<Client.HttpClient, never, never>Since v4.0.0
node:http
Section titled “node:http”layerNodeHttp
Section titled “layerNodeHttp”Provides a node:http-backed HttpClient together with default scoped Node
http and https agents.
Signature
declare const layerNodeHttp: Layer.Layer<Client.HttpClient, never, never>Since v4.0.0
layerNodeHttpNoAgent
Section titled “layerNodeHttpNoAgent”Provides a node:http-backed HttpClient using the current HttpAgent
service.
Signature
declare const layerNodeHttpNoAgent: Layer.Layer<Client.HttpClient, never, HttpAgent>Since v4.0.0
makeNodeHttp
Section titled “makeNodeHttp”Creates an HttpClient backed by Node http and https, using the
current HttpAgent, streaming request bodies, and wrapping Node responses
as HttpClientResponse values.
Signature
declare const makeNodeHttp: Effect.Effect<Client.HttpClient, never, HttpAgent>Since v4.0.0