TypeScript API / laikacms/json-api / httpClientFromFetch
Function: httpClientFromFetch()
ts
function httpClientFromFetch(fetchImpl): HttpClient;Build an Effect HttpClient backed by a specific fetch implementation.
This is the composition-root hook for TCP/TLS session reuse: on Node, pass a fetch bound to a tuned undici Agent/Pool (keep-alive timeout, max connections per origin) and every proxy repository sharing the client reuses those sockets. On Cloudflare Workers the runtime pools connections itself, so the defaultHttpClient is already optimal there.
ts
import { Agent, fetch as undiciFetch } from 'undici';
const dispatcher = new Agent({ keepAliveTimeout: 30_000, connections: 128 });
const httpClient = httpClientFromFetch(
(input, init) => undiciFetch(input, { ...init, dispatcher }),
);Clients built from @effect/platform-node's NodeHttpClient layers can be passed anywhere this one can; repositories only depend on the HttpClient.HttpClient interface.
Parameters
| Parameter | Type |
|---|---|
fetchImpl | { (input, init?): Promise<Response>; (input, init?): Promise<Response>; } |
Returns
HttpClient