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

DenoHttpServer unstable

Native Deno implementation of the Effect HttpServer.

Deno.serve can only upgrade requests to WebSocket, so other HTTP/1.1 upgrades fail. Serve them with NodeHttpServer from @effect/platform-node, which runs on Deno's node:http.

Over HTTP/1.1, Deno.serve can stop delivering the request body once the handler has returned a streamed response, so a handler that streams its response while still reading the request payload can stall (denoland/deno#36966).

Deno.serve negotiates HTTP/2 on its own: over TLS with browsers, and in cleartext with clients that request it. Deno 2.8.3 to 2.9.2 panic and exit when an HTTP/2 client cancels a request while its handler is still running (denoland/deno#36053), so this package requires Deno 2.9.3 or newer.

7 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Creates a scoped native Deno HTTP server.

Signature

declare const make: (...args: [options: any]) => Effect<{
readonly address: SocketAddress;
readonly serve: {
<E, R>(effect: Effect<HttpServerResponse, E, R>): Effect<void, never, Scope | Exclude<R, HttpServerRequest>>;
<E, R, App extends Effect<HttpServerResponse, any, any>>(effect: Effect<HttpServerResponse, E, R>, middleware: Applied<App, E, R>): Effect<void, never, Scope | Exclude<R, HttpServerRequest>>;
};
}, ServeError, Scope>

Layers

layer

unstable
Since v4.0.0

Provides a native Deno HTTP server together with Deno HTTP services.

Signature

declare function layer(options: any): Layer<HttpPlatform | Generator | DenoServices | HttpServer, ServeError>

layerConfig

unstable
Since v4.0.0

Creates the Deno HTTP server and support-services layer from configurable options.

Signature

declare function layerConfig(options: Config<any>): Layer<Path | HttpPlatform | Generator | FileSystem | HttpServer, ServeError | ConfigError>
Since v4.0.0

Provides Deno HTTP platform services and the standard Deno service set.

Signature

declare const layerHttpServices: Layer.Layer<HttpPlatform | Etag.Generator | DenoServices.DenoServices>

layerServer

unstable
Since v4.0.0

Provides only the native Deno HTTP server.

Signature

declare const layerServer: (options: ServeOptions & {
readonly disablePreemptiveShutdown?: boolean;
readonly gracefulShutdownTimeout?: Duration.Input;
readonly websocket?: Deno.UpgradeWebSocketOptions;
}) => Layer.Layer<Server.HttpServer, Error.ServeError>

Options

ServeOptions

type unstable
Since v4.0.0

Native Deno TCP, TLS, or Unix serve options managed by the scoped server.

Details

signal and onError are omitted because the scope and Effect HTTP handler own server and failure lifecycles. Server constructors additionally accept WebSocket settings that apply to every upgrade; protocol therefore cannot vary per request.

Signature

type ServeOptions = Omit<Deno.ServeTcpOptions, "signal" | "onError"> & Partial<Deno.TlsCertifiedKeyPem> | Omit<Deno.ServeUnixOptions, "signal" | "onError">

Testing

layerTest

unstable
Since v4.0.0

Starts a Deno HTTP server on an ephemeral loopback port for tests.

Signature

declare const layerTest: Layer.Layer<Server.HttpServer | HttpPlatform | FileSystem.FileSystem | Etag.Generator | Path.Path | HttpClient>