BunHttpClient unstable
Bun HTTP client built on the fetch-based HttpClient.
This module re-exports effect/http/FetchHttpClient and adds
layerOptions, which applies Bun's native fetch options, such as Unix
domain sockets and custom TLS settings, to every request.
Layers
layer
unstableLayer 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
- Fetch for supplying the fetch implementation used by this layer
- RequestInit for default
RequestInitoptions applied before request-specific fields
Signature
declare const layer: Layer.Layer<HttpClient.HttpClient>layerOptions
unstableLayer that provides an HttpClient sending every request through Bun's
fetch with the supplied native options.
When to use
Use to send every request over a Unix domain socket with { unix: path },
or over TLS with a custom CA and client certificate with
{ tls: { ca, cert, key } }.
Details
Before each request the options are merged over the RequestInit in effect
for that request: the RequestInit service in the request context, or
otherwise the one provided while building this layer. An application-wide
RequestInit for credentials, cache or default headers therefore still
applies, and the native options win per top-level key. Method, body, abort
signal and duplex mode are set per request, and request headers override
the same keys in headers.
See
- Options for the accepted fields
Signature
declare function layerOptions(options: Options): Layer<HttpClient>Example Sending requests over a Unix domain socket
import { BunHttpClient } from "@effect/platform-bun"
const DockerClient = BunHttpClient.layerOptions({ unix: "/var/run/docker.sock" })Example Mutual TLS with a private CA
import { BunHttpClient } from "@effect/platform-bun"
declare const ca: stringdeclare const cert: stringdeclare const key: string
const MtlsClient = BunHttpClient.layerOptions({ tls: { ca, cert, key } })Models
Bun fetch options applied to every request sent by layerOptions.
Details
This is Bun's BunFetchRequestInit without the fields the client sets per
request: method, body, signal and duplex. headers are merged with
the request headers, with request headers taking precedence.
Bun-specific fields include unix for a Unix domain socket path, tls for
ca, cert, key, rejectUnauthorized and checkServerIdentity, proxy,
session for a shared connection pool, protocol, decompress, verbose
and s3. Standard RequestInit fields such as credentials or redirect
are accepted too.
Signature
type Options = Omit<BunFetchRequestInit, "method" | "body" | "signal" | "duplex">Services
Fetch
unstableContext 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>RequestInit
unstableService 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);}