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

HttpIncomingMessage unstable

Common model for incoming HTTP messages.

HttpIncomingMessage is used by server requests and client responses to expose headers, an optional remote address, and body accessors. This module provides decoders for JSON bodies, URL-encoded bodies, and headers, plus the shared body-size setting and inspection helper used by request and response implementations.

9 exports Since v4.0.0 Source

Converting

inspect

unstable
Since v4.0.0

Builds an inspectable object for an incoming message, redacting headers and including a synchronously readable JSON or text body when available.

Signature

declare function inspect<E>(self: HttpIncomingMessage<E>, that: object): object

Guards

Since v4.0.0

Returns true when a value is an HttpIncomingMessage.

Signature

declare function isHttpIncomingMessage(u: unknown): u is HttpIncomingMessage<unknown>

Models

HttpIncomingMessage

interface unstable
Since v4.0.0

Common model for incoming HTTP messages, with headers, remote address, and effectful body accessors.

Signature

interface HttpIncomingMessage<E = unknown> extends Inspectable {
readonly "~effect/http/HttpIncomingMessage": "~effect/http/HttpIncomingMessage";
readonly arrayBuffer: Effect<ArrayBuffer, E>;
readonly headers: Headers;
readonly json: Effect<Json, E>;
readonly remoteAddress: Option<string>;
readonly stream: Stream<Uint8Array<ArrayBufferLike>, E>;
readonly text: Effect<string, E>;
readonly urlParamsBody: Effect<UrlParams, E>;
}

JsonOptions

interface unstable
Since v4.0.0

Options for parsing an incoming HTTP message body as JSON.

Signature

interface JsonOptions {
readonly reviver?: (this: any, key: string, value: any) => any;
}

References

MaxBodySize

unstable
Since v4.0.0

Context reference for the optional maximum size allowed when reading an incoming message body.

Signature

declare const MaxBodySize: Reference<ByteSize | undefined>

Schemas

Since v4.0.0

Creates a decoder that reads an incoming message's JSON body and decodes it with the supplied schema.

Signature

declare function schemaBodyJson<S extends Constraint>(schema: S, options?: ParseOptions & JsonOptions): <E>(self: HttpIncomingMessage<E>) => Effect<S["Type"], SchemaError | E, S["DecodingServices"]>
Since v4.0.0

Creates a decoder that reads an incoming message's URL-encoded body parameters and decodes them with the supplied schema.

Signature

declare function schemaBodyUrlParams<A, I extends Readonly<Record<string, string | readonly Array<string> | undefined>>, RD>(schema: ConstraintCodec<A, I, RD, unknown>, options?: ParseOptions): <E>(self: HttpIncomingMessage<E>) => Effect<A, SchemaError | E, RD>
Since v4.0.0

Creates a decoder that validates and decodes an incoming message's headers with the supplied schema.

Signature

declare function schemaHeaders<A, I extends Readonly<Record<string, string | undefined>>, RD>(schema: ConstraintCodec<A, I, RD, unknown>, options?: ParseOptions): <E>(self: HttpIncomingMessage<E>) => Effect<A, SchemaError, RD>

Type IDs

TypeId

unstable
Since v4.0.0

Type identifier for HttpIncomingMessage values.

Signature

declare const TypeId: "~effect/http/HttpIncomingMessage"