Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

DenoHttpClient unstable

Deno HTTP client built on the fetch-based HttpClient.

This module re-exports effect/http/FetchHttpClient and adds makeClient and layerOptions, which route every request through a Deno.HttpClient created from native Deno.createHttpClient options, such as a Unix domain socket transport or custom TLS certificates.

6 exports Since v4.0.0 Source

Constructors

makeClient

unstable
Since v4.0.6

Creates a Deno.HttpClient from the supplied options and closes it when the scope ends.

When to use

Use when you need the native client itself, for example to call fetch directly with { client } or to share one client between several layers, with the same scoped cleanup layerOptions provides. Otherwise prefer layerOptions.

Signature

declare function makeClient(options?: any): Effect<HttpClient, never, Scope>

Layers

layer

unstable
Since v4.0.0

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

  • Fetch for supplying the fetch implementation used by this layer
  • RequestInit for default RequestInit options applied before request-specific fields

Signature

declare const layer: Layer.Layer<HttpClient.HttpClient>
Since v4.0.6

Layer that provides an HttpClient sending every request through a Deno.HttpClient created with the supplied native options.

When to use

Use to send every request over a Unix domain socket with { proxy: { transport: "unix", path } }, or over TLS with a custom CA and client certificate with { caCerts: [ca], cert, key }.

Details

The native client is acquired in the layer's scope and closed when the scope ends. Before each request it is set as the client field of 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 only client is overridden. Method, headers, body and abort signal are set per request.

See

  • Options for the accepted fields and limitations
  • makeClient for acquiring the native client on its own

Signature

declare function layerOptions(options?: any): Layer<HttpClient>

Example Sending requests over a Unix domain socket

import { DenoHttpClient } from "@effect/platform-deno"
const DockerClient = DenoHttpClient.layerOptions({
proxy: { transport: "unix", path: "/var/run/docker.sock" }
})

Example Mutual TLS with a private CA

import { DenoHttpClient } from "@effect/platform-deno"
declare const ca: string
declare const cert: string
declare const key: string
const MtlsClient = DenoHttpClient.layerOptions({ caCerts: [ca], cert, key })

Models

Options

type unstable
Since v4.0.6

Options accepted by Deno.createHttpClient, used by makeClient and layerOptions.

Details

Supported fields include caCerts for additional root certificates, cert and key for a client certificate in PEM format, proxy for an alternative transport (http, https, socks5, tcp, unix or vsock), poolMaxIdlePerHost, poolIdleTimeout, http1, http2, allowHost and localAddress.

Deno has no option to skip certificate verification or to override the server name used for verification. Unix domain socket transports are not supported on Windows.

Signature

type Options = Parameters<typeof Deno.createHttpClient>[0]

Services

Fetch

unstable
Since v4.0.0

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>

RequestInit

unstable
Since v4.0.0

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);
}