HttpServerRespondable.ts
HttpServerRespondable.ts overview
Section titled “HttpServerRespondable.ts overview”Converts supported values into HTTP server responses.
Server-side errors and helper values can implement Respondable when they
know which status, headers, cookies, or body should be sent to the client.
This module detects those values and converts them to HttpServerResponse
values, with fallback handling for schema errors and missing values.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”accessors
Section titled “accessors”toResponse
Section titled “toResponse”Converts a Respondable value into an HttpServerResponse.
Details
If the value is already an HTTP server response it is returned directly; errors from the response conversion are converted to defects.
Signature
declare const toResponse: (self: Respondable) => Effect.Effect<HttpServerResponse>Since v4.0.0
toResponseOrElse
Section titled “toResponseOrElse”Attempts to convert an unknown value into an HttpServerResponse, falling back
to the supplied response when no conversion is available.
Details
HttpServerResponse and Respondable values are used directly, schema errors
become 400 responses, and no-such-element errors become 404 responses.
Signature
declare const toResponseOrElse: (u: unknown, orElse: HttpServerResponse) => Effect.Effect<HttpServerResponse>Since v4.0.0
toResponseOrElseDefect
Section titled “toResponseOrElseDefect”Attempts to convert an unknown defect into an HttpServerResponse, falling
back to the supplied response when no conversion is available.
Details
Only HttpServerResponse and Respondable values receive special handling.
Signature
declare const toResponseOrElseDefect: (u: unknown, orElse: HttpServerResponse) => Effect.Effect<HttpServerResponse>Since v4.0.0
guards
Section titled “guards”isRespondable
Section titled “isRespondable”Returns true when the supplied value implements the Respondable protocol.
Signature
declare const isRespondable: (u: unknown) => u is RespondableSince v4.0.0
models
Section titled “models”Respondable (interface)
Section titled “Respondable (interface)”Protocol for values that can be converted into an HttpServerResponse.
Details
Implement the protocol method to describe the response that should be sent for the value.
Signature
export interface Respondable { [symbol](): Effect.Effect<HttpServerResponse, unknown>}Since v4.0.0
type IDs
Section titled “type IDs”symbol
Section titled “symbol”Protocol key used by values that can render themselves as
HttpServerResponse values.
Signature
declare const symbol: "~effect/http/HttpServerRespondable"Since v4.0.0