HttpApiEndpoint.ts
HttpApiEndpoint.ts overview
Section titled “HttpApiEndpoint.ts overview”Defines endpoint declarations used inside an HTTP API group.
An endpoint records a stable name, HTTP method, router path, request schemas, response schemas, declared errors, middleware, and annotations. Endpoint values are declarations, not handlers: builders use them to decode requests, type handler input, encode responses, generate OpenAPI metadata, and derive generated-client call signatures. This module also includes HTTP method constructors, payload and response schema helpers, and type utilities used by builders and generated clients.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”- Codecs
- constraints
- constructors
- guards
- models
- AddError (type alias)
- AddMiddleware (type alias)
- AddPrefix (type alias)
- Any (interface)
- AnyWithProps (interface)
- ClientRequest (type alias)
- ClientResponseMode (type alias)
- ClientServices (type alias)
- Error (type alias)
- ErrorServicesDecode (type alias)
- ErrorServicesEncode (type alias)
- Errors (type alias)
- ErrorsWithName (type alias)
- ExcludeName (type alias)
- ExcludeProvided (type alias)
- ExcludeProvidedWithName (type alias)
- Handler (type alias)
- HandlerRaw (type alias)
- HandlerRawWithName (type alias)
- HandlerWithName (type alias)
- Headers (type alias)
- HttpApiEndpoint (interface)
- Middleware (type alias)
- MiddlewareClient (type alias)
- MiddlewareError (type alias)
- MiddlewareProvides (type alias)
- MiddlewareServices (type alias)
- MiddlewareServicesWithName (type alias)
- MiddlewareWithName (type alias)
- Name (type alias)
- Params (type alias)
- Payload (type alias)
- PayloadMap (type alias)
- Query (type alias)
- Request (type alias)
- RequestRaw (type alias)
- ServerServices (type alias)
- ServerServicesWithName (type alias)
- Success (type alias)
- SuccessWithName (type alias)
- WithName (type alias)
Codecs
Section titled “Codecs”Json (interface)
Section titled “Json (interface)”A schema codec that decodes and encodes the schema’s value type through JSON transport values.
Signature
export interface Json<S extends Schema.Constraint> extends Schema.Codec< S["Type"], Schema.Json, S["DecodingServices"], S["EncodingServices"]> {}Since v4.0.0
StringTree (interface)
Section titled “StringTree (interface)”A schema codec that decodes and encodes the schema’s value type through
Schema.StringTree transport values.
Signature
export interface StringTree<S extends Schema.Constraint> extends Schema.Codec< S["Type"], Schema.StringTree, S["DecodingServices"], S["EncodingServices"]> {}Since v4.0.0
constraints
Section titled “constraints”ErrorConstraint (type alias)
Section titled “ErrorConstraint (type alias)”Constraint for error response schemas, allowing either a single schema or a readonly array of schemas.
Signature
type ErrorConstraint = Schema.Top | ReadonlyArray<Schema.Top>Since v4.0.0
HeadersConstraint (type alias)
Section titled “HeadersConstraint (type alias)”Constraint for header schemas: each header must encode to string | undefined,
or the schema must encode to a record of those values.
Signature
type HeadersConstraint = | Record<string, Schema.Codec<unknown, string | undefined, unknown, unknown>> | Schema.Codec<unknown, Record<string, string | undefined>, unknown, unknown>Since v4.0.0
ParamsConstraint (type alias)
Section titled “ParamsConstraint (type alias)”Constraint for path parameter schemas: each parameter must encode to
string | undefined, or the schema must encode to a record of those values.
Signature
type ParamsConstraint = | Record<string, Schema.Codec<unknown, string | undefined, unknown, unknown>> | Schema.Codec<unknown, Record<string, string | undefined>, unknown, unknown>Since v4.0.0
PayloadConstraint (type alias)
Section titled “PayloadConstraint (type alias)”Payload schema depends on the HTTP method:
- for no-body methods, payload is modeled as query params, so each field must
encode to
string | ReadonlyArray<string> | undefinedand OpenAPI can expand it intoin: queryparameters - for body methods, payload may be any
Schema.Top(or content-type keyed schemas) and OpenAPI usesrequestBodyinstead ofparameters
Signature
type PayloadConstraint<Method> = Method extends HttpMethod.NoBody ? Record<string, Schema.Codec<unknown, string | ReadonlyArray<string> | undefined, unknown, unknown>> : Schema.Top | ReadonlyArray<Schema.Top>Since v4.0.0
PayloadConstraintCodecs (type alias)
Section titled “PayloadConstraintCodecs (type alias)”Payload constraint used when automatic codecs are enabled: no-body methods accept field records for query-style encoding, while body methods accept one or more schemas.
Signature
type PayloadConstraintCodecs<Method> = Method extends HttpMethod.NoBody ? Record<string, Schema.Top> : Schema.Top | ReadonlyArray<Schema.Top>Since v4.0.0
QueryConstraint (type alias)
Section titled “QueryConstraint (type alias)”Constraint for query schemas: each field must encode to string, an array of
strings, or undefined, or the schema must encode to a record of those values.
Signature
type QueryConstraint = | Record<string, Schema.Codec<unknown, string | ReadonlyArray<string> | undefined, unknown, unknown>> | Schema.Codec<unknown, string | ReadonlyArray<string> | undefined, unknown, unknown>Since v4.0.0
SuccessConstraint (type alias)
Section titled “SuccessConstraint (type alias)”Constraint for success response schemas, allowing either a single schema or a readonly array of schemas.
Signature
type SuccessConstraint = Schema.Top | ReadonlyArray<Schema.Top>Since v4.0.0
constructors
Section titled “constructors”delete
Section titled “delete”Creates a DELETE endpoint declaration.
Signature
declare const delete: { <const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never>(name: Name, path: Path, options?: { readonly disableCodecs?: false | undefined; readonly params?: Params | undefined; readonly query?: Query | undefined; readonly headers?: Headers | undefined; readonly payload?: Payload | undefined; readonly success?: Success | undefined; readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined; } | undefined): HttpApiEndpoint<Name, "DELETE", Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, Json<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error>, never, never>; <const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never>(name: Name, path: Path, options?: { readonly disableCodecs: true; readonly params?: Params | undefined; readonly query?: Query | undefined; readonly headers?: Headers | undefined; readonly payload?: Payload | undefined; readonly success?: Success | undefined; readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined; } | undefined): HttpApiEndpoint<Name, "DELETE", Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error, never, never>; }Since v4.0.0
Creates a GET endpoint declaration.
Signature
declare const get: { < const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends Record<string, Schema.Top> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never >( name: Name, path: Path, options?: | { readonly disableCodecs?: false | undefined readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "GET", Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, StringTree<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error>, never, never > < const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends Record< string, Schema.Codec<unknown, string | ReadonlyArray<string> | undefined, unknown, unknown> > = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never >( name: Name, path: Path, options?: | { readonly disableCodecs: true readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "GET", Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error, never, never >}Since v4.0.0
Creates a HEAD endpoint declaration.
Signature
declare const head: { < const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends Record<string, Schema.Top> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never >( name: Name, path: Path, options?: | { readonly disableCodecs?: false | undefined readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "HEAD", Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, StringTree<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error>, never, never > < const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends Record< string, Schema.Codec<unknown, string | ReadonlyArray<string> | undefined, unknown, unknown> > = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never >( name: Name, path: Path, options?: | { readonly disableCodecs: true readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "HEAD", Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error, never, never >}Since v4.0.0
Creates endpoint constructors for a specific HTTP method. The resulting
constructor builds an HttpApiEndpoint from a name, path, and optional request
and response schemas, applying automatic JSON or string-tree codecs unless
disableCodecs is enabled.
Signature
declare const make: <Method extends HttpMethod>( method: Method) => { < const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends PayloadConstraintCodecs<Method> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never >( name: Name, path: Path, options?: { readonly disableCodecs?: false | undefined readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } ): HttpApiEndpoint< Name, Method, Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, Method extends HttpMethod.WithBody ? Json<ExtractSchemaOrArray<Payload>> : StringTree<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error> > < const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends PayloadConstraint<Method> = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never >( name: Name, path: Path, options?: { readonly disableCodecs: true readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } ): HttpApiEndpoint< Name, Method, Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error >}Since v4.0.0
options
Section titled “options”Creates an OPTIONS endpoint declaration.
Signature
declare const options: { < const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends Record<string, Schema.Top> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never >( name: Name, path: Path, options?: | { readonly disableCodecs?: false | undefined readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "OPTIONS", Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, StringTree<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error>, never, never > < const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends Record< string, Schema.Codec<unknown, string | ReadonlyArray<string> | undefined, unknown, unknown> > = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never >( name: Name, path: Path, options?: | { readonly disableCodecs: true readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "OPTIONS", Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error, never, never >}Since v4.0.0
Creates a PATCH endpoint declaration.
Signature
declare const patch: { < const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never >( name: Name, path: Path, options?: | { readonly disableCodecs?: false | undefined readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "PATCH", Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, Json<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error>, never, never > < const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never >( name: Name, path: Path, options?: | { readonly disableCodecs: true readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "PATCH", Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error, never, never >}Since v4.0.0
Creates a POST endpoint declaration.
Signature
declare const post: { < const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never >( name: Name, path: Path, options?: | { readonly disableCodecs?: false | undefined readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "POST", Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, Json<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error>, never, never > < const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never >( name: Name, path: Path, options?: | { readonly disableCodecs: true readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "POST", Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error, never, never >}Since v4.0.0
Creates a PUT endpoint declaration.
Signature
declare const put: { < const Name extends string, const Path extends HttpRouter.PathInput, Params extends Schema.Top | Schema.Struct.Fields = never, Query extends Schema.Top | Schema.Struct.Fields = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends Schema.Top | Schema.Struct.Fields = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends Schema.Top | ReadonlyArray<Schema.Top> = never >( name: Name, path: Path, options?: | { readonly disableCodecs?: false | undefined readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "PUT", Path, StringTree<Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params>, StringTree<Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query>, Json<ExtractSchemaOrArray<Payload>>, StringTree<Headers extends Schema.Struct.Fields ? Schema.Struct<Headers> : Headers>, JsonSuccessOrArray<Success>, Json<Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error>, never, never > < const Name extends string, const Path extends HttpRouter.PathInput, Params extends ParamsConstraint = never, Query extends QueryConstraint = never, Payload extends Schema.Top | ReadonlyArray<Schema.Top> = never, Headers extends HeadersConstraint = never, const Success extends SuccessConstraint = HttpApiSchema.NoContent, const Error extends ErrorConstraint = never >( name: Name, path: Path, options?: | { readonly disableCodecs: true readonly params?: Params | undefined readonly query?: Query | undefined readonly headers?: Headers | undefined readonly payload?: Payload | undefined readonly success?: Success | undefined readonly error?: (Error & ErrorNoStream<Types.NoInfer<Error>>) | undefined } | undefined ): HttpApiEndpoint< Name, "PUT", Path, Params extends Schema.Struct.Fields ? Schema.Struct<Params> : Params, Query extends Schema.Struct.Fields ? Schema.Struct<Query> : Query, ExtractSchemaOrArray<Payload>, ExtractSchemaOrArray<Headers>, ExtractSuccessOrArray<Success>, Error extends ReadonlyArray<Schema.Constraint> ? Error[number] : Error, never, never >}Since v4.0.0
guards
Section titled “guards”isHttpApiEndpoint
Section titled “isHttpApiEndpoint”Returns true when a value is an HttpApiEndpoint, narrowing the value to the
endpoint interface.
Signature
declare const isHttpApiEndpoint: (u: unknown) => u is HttpApiEndpoint<any, any, any>Since v4.0.0
models
Section titled “models”AddError (type alias)
Section titled “AddError (type alias)”Returns an endpoint type with an additional error schema added to the endpoint’s existing error schema union.
Signature
type AddError<Endpoint, E> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? HttpApiEndpoint<_Name, _Method, _Path, _Params, _Query, _Payload, _Headers, _Success, _Error | E, _M, _MR> : neverSince v4.0.0
AddMiddleware (type alias)
Section titled “AddMiddleware (type alias)”Returns an endpoint type with additional middleware applied and the endpoint’s middleware service requirements updated accordingly.
Signature
type AddMiddleware<Endpoint, M> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? HttpApiEndpoint< _Name, _Method, _Path, _Params, _Query, _Payload, _Headers, _Success, _Error, _M | M, HttpApiMiddleware.ApplyServices<M, _MR> > : neverSince v4.0.0
AddPrefix (type alias)
Section titled “AddPrefix (type alias)”Returns an endpoint type with the supplied path prefix prepended while preserving the endpoint’s schemas, method, errors, and middleware.
Signature
type AddPrefix<Endpoint, Prefix> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? HttpApiEndpoint< _Name, _Method, `${Prefix}${_Path}`, _Params, _Query, _Payload, _Headers, _Success, _Error, _M, _MR > : neverSince v4.0.0
Any (interface)
Section titled “Any (interface)”A widened HttpApiEndpoint type used when the concrete method, path, schemas,
and middleware types are not needed.
Signature
export interface Any extends Pipeable { readonly [TypeId]: any readonly name: string readonly ["~Success"]: Schema.Top readonly ["~Error"]: Schema.Top}Since v4.0.0
AnyWithProps (interface)
Section titled “AnyWithProps (interface)”A widened endpoint type that preserves concrete runtime properties such as method, path, schemas, annotations, and middleware sets.
Signature
export interface AnyWithProps extends HttpApiEndpoint< string, HttpMethod, string, Schema.Top, Schema.Top, Schema.Top, Schema.Top, any, any> {}Since v4.0.0
ClientRequest (type alias)
Section titled “ClientRequest (type alias)”Builds the request object accepted by a generated client method, including only
the params, query, headers, payload, and response mode fields required by the
endpoint. Multipart payloads are supplied as FormData.
Signature
type ClientRequest<Params, Query, Payload, Headers, ResponseMode> = ([Params["Type"]] extends [never] ? {} : { readonly params: Params["Type"] }) & ([Query["Type"]] extends [never] ? {} : { readonly query: Query["Type"] }) & ([Headers["Type"]] extends [never] ? {} : { readonly headers: Headers["Type"] }) & ([Payload["Type"]] extends [never] ? {} : Payload["Type"] extends infer P ? P extends Brand<HttpApiSchema.MultipartTypeId> | Brand<HttpApiSchema.MultipartStreamTypeId> ? { readonly payload: FormData } : { readonly payload: Payload["Type"] } : { readonly payload: Payload["Type"] }) extends infer Req ? keyof Req extends never ? void | { readonly responseMode?: ResponseMode } : Req & { readonly responseMode?: ResponseMode } : voidSince v4.0.0
ClientResponseMode (type alias)
Section titled “ClientResponseMode (type alias)”Controls what a generated client method returns: the decoded success value, the decoded value paired with the raw response, or only the raw response.
Signature
type ClientResponseMode = "decoded-only" | "decoded-and-response" | "response-only"Since v4.0.0
ClientServices (type alias)
Section titled “ClientServices (type alias)”Computes the services required on the client to encode endpoint requests and decode endpoint success or error responses.
Signature
type ClientServices<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? | _Params["EncodingServices"] | _Query["EncodingServices"] | _Payload["EncodingServices"] | _Headers["EncodingServices"] | SuccessDecodingServices<_Success> | _Error["DecodingServices"] : neverSince v4.0.0
Error (type alias)
Section titled “Error (type alias)”Extracts the error schema associated with an endpoint.
Signature
type Error<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Error : neverSince v4.0.0
ErrorServicesDecode (type alias)
Section titled “ErrorServicesDecode (type alias)”Computes the services required to decode an endpoint’s error responses, including services required by middleware error decoders.
Signature
type ErrorServicesDecode<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Error["DecodingServices"] | HttpApiMiddleware.ErrorServicesDecode<Middleware<Endpoint>> : neverSince v4.0.0
ErrorServicesEncode (type alias)
Section titled “ErrorServicesEncode (type alias)”Computes the services required to encode an endpoint’s error responses, including services required by middleware error encoders.
Signature
type ErrorServicesEncode<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Error["EncodingServices"] | HttpApiMiddleware.ErrorServicesEncode<Middleware<Endpoint>> : neverSince v4.0.0
Errors (type alias)
Section titled “Errors (type alias)”Computes the full error value union for an endpoint, including the endpoint error schema’s type and errors introduced by middleware.
Signature
type Errors<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Error["Type"] | HttpApiMiddleware.Error<Middleware<Endpoint>> : neverSince v4.0.0
ErrorsWithName (type alias)
Section titled “ErrorsWithName (type alias)”Computes the full error value union for the endpoint with the specified name in an endpoint union.
Signature
type ErrorsWithName<Endpoints, Name> = Errors<WithName<Endpoints, Name>>Since v4.0.0
ExcludeName (type alias)
Section titled “ExcludeName (type alias)”Removes endpoints with the specified name from a union of endpoints.
Signature
type ExcludeName<Endpoints, Name> = Exclude<Endpoints, { readonly name: Name }>Since v4.0.0
ExcludeProvided (type alias)
Section titled “ExcludeProvided (type alias)”Removes services provided by the HTTP router and endpoint middleware from a service requirement union.
Signature
type ExcludeProvided<Endpoint, R> = Exclude<R, HttpRouter.Provided | HttpApiMiddleware.Provides<Middleware<Endpoint>>>Since v4.0.0
ExcludeProvidedWithName (type alias)
Section titled “ExcludeProvidedWithName (type alias)”Removes services provided by the HTTP router and the named endpoint’s middleware from a service requirement union.
Signature
type ExcludeProvidedWithName<Endpoints, Name, R> = ExcludeProvided<WithName<Endpoints, Name>, R>Since v4.0.0
Handler (type alias)
Section titled “Handler (type alias)”The normal server handler for an endpoint, accepting the decoded request shape
and returning either the endpoint success value or a custom HttpServerResponse.
Signature
type Handler<Endpoint, E, R> = ( request: Types.Simplify<Request<Endpoint>>) => Effect<SuccessType<Endpoint["~Success"]> | HttpServerResponse, Endpoint["~Error"]["Type"] | E, R>Since v4.0.0
HandlerRaw (type alias)
Section titled “HandlerRaw (type alias)”The raw server handler for an endpoint, receiving a request shape without a
decoded payload so the handler can read the raw HttpServerRequest directly.
Signature
type HandlerRaw<Endpoint, E, R> = ( request: Types.Simplify<RequestRaw<Endpoint>>) => Effect<SuccessType<Endpoint["~Success"]> | HttpServerResponse, Endpoint["~Error"]["Type"] | E, R>Since v4.0.0
HandlerRawWithName (type alias)
Section titled “HandlerRawWithName (type alias)”Derives the raw handler type for the endpoint with the specified name in an endpoint union.
Signature
type HandlerRawWithName<Endpoints, Name, E, R> = HandlerRaw<WithName<Endpoints, Name>, E, R>Since v4.0.0
HandlerWithName (type alias)
Section titled “HandlerWithName (type alias)”Derives the normal handler type for the endpoint with the specified name in an endpoint union.
Signature
type HandlerWithName<Endpoints, Name, E, R> = Handler<WithName<Endpoints, Name>, E, R>Since v4.0.0
Headers (type alias)
Section titled “Headers (type alias)”Extracts the schema used for an endpoint’s request headers.
Signature
type Headers<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Headers : neverSince v4.0.0
HttpApiEndpoint (interface)
Section titled “HttpApiEndpoint (interface)”Represents an API endpoint. An API endpoint is mapped to a single route on
the underlying HttpRouter.
Signature
export interface HttpApiEndpoint< out Name extends string, out Method extends HttpMethod, out Path extends string, out Params extends Schema.Top = never, out Query extends Schema.Top = never, out Payload extends Schema.Top = never, out Headers extends Schema.Top = never, out Success extends Schema.Top = typeof HttpApiSchema.NoContent, out Error extends Schema.Top = never, in out Middleware = never, out MiddlewareR = never> extends Pipeable { readonly [TypeId]: { readonly _MiddlewareR: Types.Covariant<MiddlewareR> } readonly "~Params": Params readonly "~Query": Query readonly "~Headers": Headers readonly "~Payload": Payload readonly "~Success": Success readonly "~Error": Error
readonly name: Name readonly path: Path readonly method: Method readonly params: Schema.Top | undefined readonly query: Schema.Top | undefined readonly headers: Schema.Top | undefined readonly payload: PayloadMap readonly success: ReadonlySet<Schema.Top> readonly error: ReadonlySet<Schema.Top> readonly annotations: Context.Context<never> readonly middlewares: ReadonlySet<Context.Key<Middleware, any>>
/** * Add a prefix to the path of the endpoint. */ prefix<const Prefix extends HttpRouter.PathInput>( prefix: Prefix ): HttpApiEndpoint< Name, Method, `${Prefix}${Path}`, Params, Query, Payload, Headers, Success, Error, Middleware, MiddlewareR >
/** * Add an `HttpApiMiddleware` to the endpoint. */ middleware<I extends HttpApiMiddleware.AnyId, S>( middleware: Context.Key<I, S> ): HttpApiEndpoint< Name, Method, Path, Params, Query, Payload, Headers, Success, Error, Middleware | I, HttpApiMiddleware.ApplyServices<I, MiddlewareR> >
/** * Add an annotation on the endpoint. */ annotate<I, S>( key: Context.Key<I, S>, value: Types.NoInfer<S> ): HttpApiEndpoint<Name, Method, Path, Params, Query, Payload, Headers, Success, Error, Middleware, MiddlewareR>
/** * Merge the annotations of the endpoint with the provided context. */ annotateMerge<I>( annotations: Context.Context<I> ): HttpApiEndpoint<Name, Method, Path, Params, Query, Payload, Headers, Success, Error, Middleware, MiddlewareR>}Since v4.0.0
Middleware (type alias)
Section titled “Middleware (type alias)”Extracts the middleware identifiers attached to an endpoint.
Signature
type Middleware<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _M : neverSince v4.0.0
MiddlewareClient (type alias)
Section titled “MiddlewareClient (type alias)”Computes the client-side middleware services required by an endpoint.
Signature
type MiddlewareClient<Endpoint> = HttpApiMiddleware.MiddlewareClient<Middleware<Endpoint>>Since v4.0.0
MiddlewareError (type alias)
Section titled “MiddlewareError (type alias)”Computes the error types that can be produced by the middleware attached to an endpoint.
Signature
type MiddlewareError<Endpoint> = HttpApiMiddleware.Error<Middleware<Endpoint>>Since v4.0.0
MiddlewareProvides (type alias)
Section titled “MiddlewareProvides (type alias)”Computes the services provided by the middleware attached to an endpoint.
Signature
type MiddlewareProvides<Endpoint> = HttpApiMiddleware.Provides<Middleware<Endpoint>>Since v4.0.0
MiddlewareServices (type alias)
Section titled “MiddlewareServices (type alias)”Extracts the additional services required by middleware applied to an endpoint.
Signature
type MiddlewareServices<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _MR : neverSince v4.0.0
MiddlewareServicesWithName (type alias)
Section titled “MiddlewareServicesWithName (type alias)”Extracts the middleware service requirements for the endpoint with the specified name in an endpoint union.
Signature
type MiddlewareServicesWithName<Endpoints, Name> = MiddlewareServices<WithName<Endpoints, Name>>Since v4.0.0
MiddlewareWithName (type alias)
Section titled “MiddlewareWithName (type alias)”Extracts the middleware identifiers for the endpoint with the specified name in an endpoint union.
Signature
type MiddlewareWithName<Endpoints, Name> = Middleware<WithName<Endpoints, Name>>Since v4.0.0
Name (type alias)
Section titled “Name (type alias)”Extracts the name literal from an HttpApiEndpoint.
Signature
type Name<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Name : neverSince v4.0.0
Params (type alias)
Section titled “Params (type alias)”Extracts the schema used for an endpoint’s path parameters.
Signature
type Params<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Params : neverSince v4.0.0
Payload (type alias)
Section titled “Payload (type alias)”Extracts the schema used for an endpoint’s request payload.
Signature
type Payload<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Payload : neverSince v4.0.0
PayloadMap (type alias)
Section titled “PayloadMap (type alias)”Maps content types to the payload encoding strategy and one or more schemas that can decode or encode payloads for that content type.
Signature
type PayloadMap = ReadonlyMap< string, { readonly encoding: HttpApiSchema.PayloadEncoding readonly schemas: [Schema.Top, ...Array<Schema.Top>] }>Since v4.0.0
Query (type alias)
Section titled “Query (type alias)”Extracts the schema used for an endpoint’s query parameters.
Signature
type Query<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Query : neverSince v4.0.0
Request (type alias)
Section titled “Request (type alias)”Builds the decoded request shape passed to a normal endpoint handler, including available params, query, payload, headers, the raw request, endpoint, and group. Multipart stream payloads are exposed as streams of parts.
Signature
type Request<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? ([_Params["Type"]] extends [never] ? {} : { readonly params: _Params["Type"] }) & ([_Query["Type"]] extends [never] ? {} : { readonly query: _Query["Type"] }) & ([_Payload["Type"]] extends [never] ? {} : _Payload["Type"] extends Brand<HttpApiSchema.MultipartStreamTypeId> ? { readonly payload: Stream.Stream<Multipart.Part, Multipart.MultipartError> } : { readonly payload: _Payload["Type"] }) & ([_Headers] extends [never] ? {} : { readonly headers: _Headers["Type"] }) & { readonly request: HttpServerRequest readonly endpoint: Endpoint readonly group: HttpApiGroup.AnyWithProps } : {}Since v4.0.0
RequestRaw (type alias)
Section titled “RequestRaw (type alias)”Builds the request shape passed to a raw endpoint handler, including decoded params, query, and headers plus the raw request, endpoint, and group, while leaving payload handling to the raw request.
Signature
type RequestRaw<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? ([_Params["Type"]] extends [never] ? {} : { readonly params: _Params["Type"] }) & ([_Query["Type"]] extends [never] ? {} : { readonly query: _Query["Type"] }) & ([_Headers["Type"]] extends [never] ? {} : { readonly headers: _Headers["Type"] }) & { readonly request: HttpServerRequest readonly endpoint: Endpoint readonly group: HttpApiGroup.AnyWithProps } : {}Since v4.0.0
ServerServices (type alias)
Section titled “ServerServices (type alias)”Computes the services required on the server to decode endpoint inputs and encode endpoint success, error, and middleware error responses.
Signature
type ServerServices<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? | _Params["DecodingServices"] | _Query["DecodingServices"] | _Payload["DecodingServices"] | _Headers["DecodingServices"] | SuccessEncodingServices<_Success> | _Error["EncodingServices"] | HttpApiMiddleware.ErrorServicesEncode<_M> : neverSince v4.0.0
ServerServicesWithName (type alias)
Section titled “ServerServicesWithName (type alias)”Computes the server-side service requirements for the endpoint with the specified name in an endpoint union.
Signature
type ServerServicesWithName<Endpoints, Name> = ServerServices<WithName<Endpoints, Name>>Since v4.0.0
Success (type alias)
Section titled “Success (type alias)”Extracts the success schema associated with an endpoint.
Signature
type Success<Endpoint> = Endpoint extends HttpApiEndpoint< infer _Name, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _M, infer _MR > ? _Success : neverSince v4.0.0
SuccessWithName (type alias)
Section titled “SuccessWithName (type alias)”Extracts the decoded success value type for the endpoint with the specified name in an endpoint union.
Signature
type SuccessWithName<Endpoints, Name> = Success<WithName<Endpoints, Name>> extends infer S ? SuccessType<S> : neverSince v4.0.0
WithName (type alias)
Section titled “WithName (type alias)”Selects the endpoint with the specified name from a union of endpoints.
Signature
type WithName<Endpoints, Name> = Extract<Endpoints, { readonly name: Name }>Since v4.0.0