HttpApiSchema.ts
HttpApiSchema.ts overview
Section titled “HttpApiSchema.ts overview”Attaches HTTP API metadata to Effect Schema values.
This module is the schema-side bridge for HttpApi endpoint builders, generated clients, and OpenAPI support. It does not define routes or perform IO. Instead, the helpers annotate schemas so the surrounding HTTP API tooling can choose response status codes, content types, body codecs, multipart handling, and no-body response behavior.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”Accepted
Section titled “Accepted”Schema for empty HTTP responses with status code 202.
Signature
declare const Accepted: AcceptedSince v4.0.0
Created
Section titled “Created”Schema for empty HTTP responses with status code 201.
Signature
declare const Created: CreatedSince v4.0.0
Creates a void schema with the given HTTP status code. This is used to represent empty responses with a specific status code.
See
NoContentfor the predefined 204 no content schema.
Signature
declare const Empty: (code: number) => Schema.VoidSince v4.0.0
NoContent
Section titled “NoContent”Schema for empty HTTP responses with status code 204.
Signature
declare const NoContent: NoContentSince v4.0.0
constructors
Section titled “constructors”StreamSse
Section titled “StreamSse”Creates a Server-Sent Events streaming success response schema.
Signature
declare const StreamSse: { <Events extends Sse.EventCodec, Error extends Schema.Constraint = Schema.Never>(options: { readonly contentType?: string | undefined readonly events: Events readonly error?: Error | undefined }): StreamSse<Events, Error, Events["Type"]> <Data extends Schema.Constraint, Error extends Schema.Constraint = Schema.Never>(options: { readonly contentType?: string | undefined readonly data: Data readonly error?: Error | undefined }): StreamSse<SseEventFromData<Data>, Error, Data["Type"]>}Since v4.0.0
StreamUint8Array
Section titled “StreamUint8Array”Creates a streaming Uint8Array success response schema.
Signature
declare const StreamUint8Array: (options?: { readonly contentType?: string | undefined }) => StreamUint8ArraySince v4.0.0
encoding
Section titled “encoding”asFormUrlEncoded
Section titled “asFormUrlEncoded”Marks a schema as an application/x-www-form-urlencoded payload or response.
Details
The schema’s encoded side must be a record of strings.
Signature
declare const asFormUrlEncoded: (options?: { readonly contentType?: string}) => <S extends Schema.Top>(self: S) => S["Rebuild"]Since v4.0.0
asJson
Section titled “asJson”Marks a schema as a JSON payload / response.
Signature
declare const asJson: (options?: { readonly contentType?: string }) => <S extends Schema.Top>(self: S) => S["Rebuild"]Since v4.0.0
asMultipart
Section titled “asMultipart”Marks a schema as a multipart payload.
See
asMultipartStreamfor a multipart stream payload.
Signature
declare const asMultipart: ( options?: Multipart_.withLimits.Options) => <S extends Schema.Top>(self: S) => asMultipart<S>Since v4.0.0
asMultipartStream
Section titled “asMultipartStream”Marks a schema as a multipart stream payload.
See
asMultipartfor a buffered multipart payload.
Signature
declare const asMultipartStream: ( options?: Multipart_.withLimits.Options) => <S extends Schema.Top>(self: S) => asMultipartStream<S>Since v4.0.0
asNoContent
Section titled “asNoContent”Marks a schema as a no-content response while preserving a decoded client value.
Details
The server encodes the response as void; generated clients call decode to
produce the schema’s decoded value when the response has no body.
See
NoContentfor a void schema with the status code 204.Emptyfor creating a void schema with a specific status code.
Signature
declare const asNoContent: <S extends Schema.Constraint>(options: { readonly decode: LazyArg<S["Type"]>}) => (self: S) => asNoContent<S>Since v4.0.0
asText
Section titled “asText”Marks a schema as a text payload / response.
Details
The schema encoded side must be a string.
Signature
declare const asText: (options?: { readonly contentType?: string}) => <S extends Schema.Top & { readonly Encoded: string }>(self: S) => S["Rebuild"]Since v4.0.0
asUint8Array
Section titled “asUint8Array”Marks a schema as a binary payload / response.
Details
The schema encoded side must be a Uint8Array.
Signature
declare const asUint8Array: (options?: { readonly contentType?: string}) => <S extends Schema.Top & { readonly Encoded: Uint8Array }>(self: S) => S["Rebuild"]Since v4.0.0
models
Section titled “models”Accepted (interface)
Section titled “Accepted (interface)”Type of the Accepted schema, a void schema annotated with HTTP status code 202.
Signature
export interface Accepted extends Schema.Void {}Since v4.0.0
Created (interface)
Section titled “Created (interface)”Type of the Created schema, a void schema annotated with HTTP status code 201.
Signature
export interface Created extends Schema.Void {}Since v4.0.0
Encoding (type alias)
Section titled “Encoding (type alias)”HTTP API body encoding metadata used by payloads and responses.
Signature
type Encoding = PayloadEncoding | ResponseEncodingSince v4.0.0
NoContent (interface)
Section titled “NoContent (interface)”Type of the NoContent schema, a void schema annotated with HTTP status code 204.
Signature
export interface NoContent extends Schema.Void {}Since v4.0.0
PayloadEncoding (type alias)
Section titled “PayloadEncoding (type alias)”HTTP API request payload encoding metadata.
Signature
type PayloadEncoding = | { readonly _tag: "Multipart" readonly mode: "buffered" | "stream" readonly contentType: string readonly limits?: Multipart_.withLimits.Options | undefined } | { readonly _tag: "Json" | "FormUrlEncoded" | "Uint8Array" | "Text" readonly contentType: string }Since v4.0.0
ResponseEncoding (type alias)
Section titled “ResponseEncoding (type alias)”HTTP API response body encoding metadata.
Signature
type ResponseEncoding = { readonly _tag: "Json" | "FormUrlEncoded" | "Uint8Array" | "Text" readonly contentType: string}Since v4.0.0
SseEventFromData (interface)
Section titled “SseEventFromData (interface)”Event schema produced when StreamSse is constructed from a JSON data schema.
Signature
export interface SseEventFromData<Data extends Schema.Constraint> extends Schema.Codec< { readonly id: string | undefined readonly event: string readonly data: Data["Type"] }, { readonly id?: string | undefined readonly event?: string | undefined readonly data: string }, Data["DecodingServices"], Data["EncodingServices"]> {}Since v4.0.0
StreamSchema (type alias)
Section titled “StreamSchema (type alias)”Schema for a streaming HTTP API success response.
Signature
type StreamSchema = StreamSse<Sse.EventCodec, Schema.Top, unknown> | StreamUint8ArraySince v4.0.0
StreamSse (interface)
Section titled “StreamSse (interface)”Schema for a Server-Sent Events success response.
Details
events describes successful application events emitted by the stream, and
error describes typed stream failures that will be encoded by later
endpoint/server/client integrations using the reserved failure event. If
error is omitted, it defaults to Schema.Never. When StreamSse is
constructed from data, handlers and clients expose raw data values while
the server and client still use an SSE event schema internally.
Signature
export interface StreamSse< Events extends Sse.EventCodec, Error extends Schema.Constraint, Value = Events["Type"]> extends Schema.BottomLazy<SchemaAST.Declaration, StreamSse<Events, Error, Value>> { readonly Type: Stream.Stream<Value, Error["Type"], never> readonly Encoded: Stream.Stream<Value, Error["Type"], never> readonly DecodingServices: Events["DecodingServices"] | Error["DecodingServices"] readonly EncodingServices: Events["EncodingServices"] | Error["EncodingServices"] readonly Rebuild: StreamSse<Events, Error, Value> readonly "~type.make.in": Stream.Stream<Value, Error["Type"], never> readonly "~type.make": Stream.Stream<Value, Error["Type"], never> readonly Iso: Stream.Stream<Value, Error["Type"], never> readonly [StreamSchemaTypeId]: typeof StreamSchemaTypeId readonly _tag: "StreamSse" readonly mode: "sse" readonly sseMode: StreamSseMode readonly contentType: string readonly events: Events readonly error: Error readonly "~Value"?: Value | undefined}Since v4.0.0
StreamSseMode (type alias)
Section titled “StreamSseMode (type alias)”Mode describing whether an SSE stream emits full events or raw data values.
Signature
type StreamSseMode = "events" | "data"Since v4.0.0
StreamUint8Array (interface)
Section titled “StreamUint8Array (interface)”Schema for a streaming Uint8Array success response.
Details
This declaration stores the response content type for later endpoint,
server, client, and OpenAPI integrations. It is intentionally separate from
the buffered asUint8Array response encoding.
Signature
export interface StreamUint8Array extends Schema.Bottom< Stream.Stream<Uint8Array, unknown, never>, Stream.Stream<Uint8Array, unknown, never>, never, never, SchemaAST.Declaration, StreamUint8Array> { readonly Rebuild: StreamUint8Array readonly [StreamSchemaTypeId]: typeof StreamSchemaTypeId readonly _tag: "StreamUint8Array" readonly mode: "uint8array" readonly contentType: string}Since v4.0.0
predicates
Section titled “predicates”isNoContent
Section titled “isNoContent”Returns true when a schema AST represents a no-content response.
Details
The check succeeds for direct void schemas and schemas whose encoded or
transformation target is void.
Signature
declare const isNoContent: (ast: SchemaAST.AST) => booleanSince v4.0.0
schemas
Section titled “schemas”asMultipart (interface)
Section titled “asMultipart (interface)”Schema type returned by asMultipart for buffered multipart payloads.
Signature
export interface asMultipart<S extends Schema.Top> extends Schema.brand<S["Rebuild"], MultipartTypeId> {}Since v4.0.0
asMultipartStream (interface)
Section titled “asMultipartStream (interface)”Schema type returned by asMultipartStream for streaming multipart payloads.
Signature
export interface asMultipartStream<S extends Schema.Top> extends Schema.brand<S["Rebuild"], MultipartStreamTypeId> {}Since v4.0.0
asNoContent (interface)
Section titled “asNoContent (interface)”Schema type returned by asNoContent, encoding as void while decoding to the original schema type.
Signature
export interface asNoContent<S extends Schema.Constraint> extends Schema.decodeTo<Schema.toType<S>, Schema.Void> {}Since v4.0.0
status
Section titled “status”StatusLiteral (type alias)
Section titled “StatusLiteral (type alias)”Common HTTP status code literals accepted by status.
Signature
type StatusLiteral = keyof typeof statusCodeByLiteralSince v4.0.0
status
Section titled “status”Sets the HTTP status code of a schema.
Details
This is equivalent to calling .annotate({ httpApiStatus: code }) on the
schema. You can pass either a numeric status code (for example, 201) or a
common literal name (for example, "Created").
Signature
declare const status: { (code: number): { <S extends Schema.Top>(self: S): S["Rebuild"] } (code: StatusLiteral): { <S extends Schema.Top>(self: S): S["Rebuild"] }}Since v4.0.0
type IDs
Section titled “type IDs”MultipartStreamTypeId
Section titled “MultipartStreamTypeId”Runtime brand key used to mark schemas as streaming multipart payloads.
Signature
declare const MultipartStreamTypeId: "~effect/httpapi/HttpApiSchema/MultipartStream"Since v4.0.0
MultipartStreamTypeId (type alias)
Section titled “MultipartStreamTypeId (type alias)”Type-level brand identifier used by asMultipartStream.
Signature
type MultipartStreamTypeId = typeof MultipartStreamTypeIdSince v4.0.0
MultipartTypeId
Section titled “MultipartTypeId”Runtime brand key used to mark schemas as buffered multipart payloads.
Signature
declare const MultipartTypeId: "~effect/httpapi/HttpApiSchema/Multipart"Since v4.0.0
MultipartTypeId (type alias)
Section titled “MultipartTypeId (type alias)”Type-level brand identifier used by asMultipart.
Signature
type MultipartTypeId = typeof MultipartTypeIdSince v4.0.0