HttpClientResponse.ts
HttpClientResponse.ts overview
Section titled “HttpClientResponse.ts overview”Represents responses returned by the Effect HTTP client.
An HttpClientResponse keeps the original request together with the response
status, headers, cookies, and body accessors from the shared incoming-message
model. This module includes constructors, schema-based decoders, helpers for
streaming response bodies, and utilities for matching or filtering by HTTP
status.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”accessors
Section titled “accessors”stream
Section titled “stream”Converts an effect producing an HttpClientResponse into a stream of response body bytes.
Signature
declare const stream: <E, R>( effect: Effect.Effect<HttpClientResponse, E, R>) => Stream.Stream<Uint8Array, Error.HttpClientError | E, R>Since v4.0.0
constructors
Section titled “constructors”fromWeb
Section titled “fromWeb”Wraps a Web Response and its original HttpClientRequest as an HttpClientResponse.
Signature
declare const fromWeb: (request: HttpClientRequest.HttpClientRequest, source: Response) => HttpClientResponseSince v4.0.0
filters
Section titled “filters”filterStatus
Section titled “filterStatus”Succeeds with the response when its status satisfies the predicate, otherwise fails with HttpClientError.
Signature
declare const filterStatus: { ( f: (status: number) => boolean ): (self: HttpClientResponse) => Effect.Effect<HttpClientResponse, Error.HttpClientError> (self: HttpClientResponse, f: (status: number) => boolean): Effect.Effect<HttpClientResponse, Error.HttpClientError>}Since v4.0.0
filterStatusOk
Section titled “filterStatusOk”Succeeds with the response only when its status is in the 2xx range, otherwise fails with HttpClientError.
Signature
declare const filterStatusOk: (self: HttpClientResponse) => Effect.Effect<HttpClientResponse, Error.HttpClientError>Since v4.0.0
models
Section titled “models”HttpClientResponse (interface)
Section titled “HttpClientResponse (interface)”Model of an HTTP client response, including the original request, status, cookies, headers, and body accessors.
Signature
export interface HttpClientResponse extends HttpIncomingMessage.HttpIncomingMessage<Error.HttpClientError>, Pipeable { readonly [TypeId]: typeof TypeId readonly request: HttpClientRequest.HttpClientRequest readonly status: number readonly cookies: Cookies.Cookies readonly formData: Effect.Effect<FormData, Error.HttpClientError>}Since v4.0.0
pattern matching
Section titled “pattern matching”matchStatus
Section titled “matchStatus”Pattern matches on a response status, checking exact status handlers before status-class handlers and orElse.
Signature
declare const matchStatus: { < const Cases extends { readonly [status: number]: (_: HttpClientResponse) => any readonly "2xx"?: (_: HttpClientResponse) => any readonly "3xx"?: (_: HttpClientResponse) => any readonly "4xx"?: (_: HttpClientResponse) => any readonly "5xx"?: (_: HttpClientResponse) => any readonly orElse: (_: HttpClientResponse) => any } >( cases: Cases ): (self: HttpClientResponse) => Cases[keyof Cases] extends (_: any) => infer R ? Unify<R> : never < const Cases extends { readonly [status: number]: (_: HttpClientResponse) => any readonly "2xx"?: (_: HttpClientResponse) => any readonly "3xx"?: (_: HttpClientResponse) => any readonly "4xx"?: (_: HttpClientResponse) => any readonly "5xx"?: (_: HttpClientResponse) => any readonly orElse: (_: HttpClientResponse) => any } >( self: HttpClientResponse, cases: Cases ): Cases[keyof Cases] extends (_: any) => infer R ? Unify<R> : never}Since v4.0.0
schemas
Section titled “schemas”schemaBodyJson
Section titled “schemaBodyJson”Creates a decoder that reads a response JSON body and decodes it with the supplied schema.
Signature
declare const schemaBodyJson: <S extends Schema.Constraint>( schema: S, options?: ParseOptions | undefined) => <E>( self: HttpIncomingMessage.HttpIncomingMessage<E>) => Effect.Effect<S["Type"], E | Schema.SchemaError, S["DecodingServices"]>Since v4.0.0
schemaBodyUrlParams
Section titled “schemaBodyUrlParams”Creates a decoder that reads response URL-encoded body parameters and decodes them with the supplied schema.
Signature
declare const schemaBodyUrlParams: < A, I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>, RD, RE>( schema: Schema.Codec<A, I, RD, RE>, options?: ParseOptions | undefined) => <E>(self: HttpIncomingMessage.HttpIncomingMessage<E>) => Effect.Effect<A, E | Schema.SchemaError, RD>Since v4.0.0
schemaHeaders
Section titled “schemaHeaders”Creates a decoder that validates and decodes response headers with the supplied schema.
Signature
declare const schemaHeaders: <A, I extends Readonly<Record<string, string | undefined>>, RD, RE>( schema: Schema.Codec<A, I, RD, RE>, options?: ParseOptions | undefined) => <E>(self: HttpIncomingMessage.HttpIncomingMessage<E>) => Effect.Effect<A, Schema.SchemaError, RD>Since v4.0.0
schemaJson
Section titled “schemaJson”Creates a decoder for a response’s status, headers, and JSON body using the supplied schema.
Signature
declare const schemaJson: < A, I extends { readonly status?: number | undefined readonly headers?: Readonly<Record<string, string | undefined>> | undefined readonly body?: unknown }, RD, RE>( schema: Schema.Codec<A, I, RD, RE>, options?: ParseOptions | undefined) => (self: HttpClientResponse) => Effect.Effect<A, Schema.SchemaError | Error.HttpClientError, RD>Since v4.0.0
schemaNoBody
Section titled “schemaNoBody”Creates a decoder for a response’s status and headers without reading a response body.
Signature
declare const schemaNoBody: < A, I extends { readonly status?: number | undefined; readonly headers?: Readonly<Record<string, string>> | undefined }, RD, RE>( schema: Schema.Codec<A, I, RD, RE>, options?: ParseOptions | undefined) => (self: HttpClientResponse) => Effect.Effect<A, Schema.SchemaError, RD>Since v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Type identifier for HttpClientResponse values.
Signature
declare const TypeId: "~effect/http/HttpClientResponse"Since v4.0.0