HttpServer
Service for serving Effect HTTP responses on a concrete HTTP server.
Platform adapters provide HttpServer, and routers or applications consume
it to run an HttpServerResponse effect for each incoming request. The
service exposes the listening address, while this module also includes helpers
for address formatting, server logging, and clients that target the current
server in tests.
Accessors
addressFormattedWith
Reads the current server address, formats it with formatAddress, and passes
the formatted address to the supplied effectful function.
Signature
declare function addressFormattedWith<A, E, R>(f: (address: string) => Effect<A, E, R>): Effect<A, E, HttpServer | R>serveEffect
Effect that starts serving an HTTP response effect with the current
HttpServer.
Details
The request service is supplied by the server for each request; the effect requires a scope and any non-request dependencies of the response effect or middleware.
Signature
declare const serveEffect: { (): <E, R>(effect: Effect<HttpServerResponse, E, R>) => Effect<void, never, Scope | HttpServer | Exclude<R, HttpServerRequest>>; <E, R, App extends Effect<HttpServerResponse, any, any>>(middleware: Applied<App, E, R>): (effect: Effect<HttpServerResponse, E, R>) => Effect<void, never, Scope | HttpServer | Exclude<Services<App>, HttpServerRequest>>; <E, R>(effect: Effect<HttpServerResponse, E, R>): Effect<void, never, Scope | HttpServer | 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 | HttpServer | Exclude<Services<App>, HttpServerRequest>>;}Constructors
Constructs an HttpServer service from a serving implementation and listening
address.
Signature
declare function make(options: { readonly address: SocketAddress; readonly serve: (httpEffect: Effect<HttpServerResponse, unknown, Scope | HttpServerRequest>, middleware?: HttpMiddleware) => Effect<void, never, Scope>;}): { 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>>; };}Converting
formatAddress
Formats a server address as a display string using NetAddress.formatUrlUnsafe.
Gotchas
Throws a NetAddressError when URL conversion fails, including for scoped
IPv6 addresses. Unix socket paths are displayed with a unix:// prefix.
Signature
declare const formatAddress: (address: NetAddress.SocketAddress) => stringLayers
Creates a layer that starts serving an HTTP response effect with the current
HttpServer.
Details
The request service is supplied by the server for each request; the returned layer still requires the server, a scope, and any non-request dependencies of the response effect or middleware.
Signature
declare const serve: { (): <E, R>(effect: Effect<HttpServerResponse, E, R>) => Layer<never, never, HttpServer | Exclude<R, Scope | HttpServerRequest>>; <E, R, App extends Effect<HttpServerResponse, any, any>>(middleware: Applied<App, E, R>): (effect: Effect<HttpServerResponse, E, R>) => Layer<never, never, HttpServer | Exclude<Services<App>, Scope | HttpServerRequest>>; <E, R>(effect: Effect<HttpServerResponse, E, R>): Layer<never, never, HttpServer | Exclude<R, Scope | HttpServerRequest>>; <E, R, App extends Effect<HttpServerResponse, any, any>>(effect: Effect<HttpServerResponse, E, R>, middleware: Applied<App, E, R>): Layer<never, never, HttpServer | Exclude<Services<App>, Scope | HttpServerRequest>>;}withLogAddress
Adds address logging to a layer that provides an HttpServer.
Signature
declare function withLogAddress<A, E, R>(layer: Layer<A, E, R>): Layer<A, E, R | Exclude<HttpServer, A>>Logging
logAddress
Logs the formatted address of the current HTTP server.
Signature
declare const logAddress: Effect.Effect<void, never, HttpServer>Services
HttpServer
Service tag for an HTTP server runtime.
Details
The service can serve an HTTP response effect and exposes the address where the server is listening.
Signature
declare class HttpServer extends Shape<"effect/http/HttpServer", { 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>>; };}, this> { constructor(_: never);}Testing
layerServices
Layer that provides the platform services commonly needed by HTTP server tests.
Details
It includes HttpPlatform, Path, a weak ETag generator, and a no-op
FileSystem.
Signature
declare const layerServices: Layer.Layer<Path.Path | HttpPlatform.HttpPlatform | FileSystem.FileSystem | Etag.Generator>layerTestClient
Layer that provides the test HttpClient created by makeTestClient.
Signature
declare const layerTestClient: Layer.Layer<HttpClient.HttpClient, never, HttpServer | HttpClient.HttpClient>makeTestClient
Builds an HttpClient that sends requests to the current test HTTP server.
Details
For internet servers, requests are prefixed with the server URL and unspecified
addresses are replaced by IPv4 loopback, including dual-stack :: listeners.
Gotchas
Unix socket addresses and scoped IPv6 addresses are not supported.
Signature
declare const makeTestClient: Effect.Effect<HttpClient.HttpClient, never, HttpServer | HttpClient.HttpClient>