Skip to content
// EFFECT DAYS 2026

HttpApi unstable

Describes an Effect HTTP API as groups of endpoints.

An HttpApi value is data: it has an identifier, annotations, and groups of endpoints that describe request inputs, responses, middleware, and route metadata. The same description can be used by server builders, generated clients, URL builders, OpenAPI generation, and reflection tools.

15 exports Since v4.0.0 Source

Constructors

make

unstable
Since v4.0.0

Creates an empty HttpApi with the supplied identifier.

When to use

Use when you need to start defining an HTTP API, add groups with add or addHttpApi, provide endpoint implementations with HttpApiBuilder.group, and register the API with HttpApiBuilder.layer.

Signature

declare function make<Id extends string>(identifier: Id): HttpApi<Id, never>

Guards

isHttpApi

unstable
Since v4.0.0

Returns true when a value is an HttpApi.

Signature

declare function isHttpApi(u: unknown): u is Top

Models

Constraint

interface unstable
Since v4.0.0

An HttpApi value with its identifier and group types erased.

Signature

interface Constraint {
readonly "~effect/http-api/HttpApi": "~effect/http-api/HttpApi";
}

HttpApi

interface unstable
Since v4.0.0

An HttpApi is a collection of HTTP API groups and endpoints that represents a portion of your domain.

When to use

Use when endpoint implementations can be provided with HttpApiBuilder.group, and the completed API can be registered with HttpApiBuilder.layer.

Signature

interface HttpApi<out Id extends string, in out Groups extends HttpApiGroup.Constraint = never> extends Pipeable {
constructor(_: never);
readonly "~effect/http-api/HttpApi": "~effect/http-api/HttpApi";
readonly annotations: Context<never>;
readonly groups: GroupMap<Groups>;
readonly identifier: Id;
add<A extends readonly [Constraint, Constraint]>(...groups: A): HttpApi<Id, Groups | A[number]>;
addHttpApi<Id2 extends string, Groups2 extends Constraint>(api: HttpApi<Id2, Groups2>): HttpApi<Id, Groups | Groups2>;
annotate<I, S>(tag: Key<I, S>, value: S): HttpApi<Id, Groups>;
annotateMerge<I>(context: Context<I>): HttpApi<Id, Groups>;
middleware<I extends AnyId, S>(middleware: Key<I, S>): HttpApi<Id, AddMiddleware<Groups, I>>;
prefix<Prefix extends PathInput>(prefix: Prefix): HttpApi<Id, AddPrefix<Groups, Prefix>>;
}

Top

interface unstable
Since v4.0.0

An HttpApi with broad identifier and group types while retaining the concrete runtime properties used by implementation helpers.

Signature

interface Top extends HttpApi<string, HttpApiGroup.Top> {
constructor(_: never);
}

Reflection

reflect

unstable
Since v4.0.0

Describes the groups and endpoints in an HttpApi.

Details

The callbacks receive each group or endpoint with merged annotations, endpoint middleware, and response schemas grouped by HTTP status.

Signature

declare function reflect<Id extends string, Groups extends Constraint>(self: HttpApi<Id, Groups>, options: {
readonly onEndpoint: (options: {
readonly endpoint: Top;
readonly errors: ReadonlyMap<number, readonly [Top, Top]>;
readonly group: Top;
readonly mergedAnnotations: Context<never>;
readonly middleware: ReadonlySet<AnyService>;
readonly successes: ReadonlyMap<number, readonly [Top, Top]>;
}) => void;
readonly onGroup: (options: {
readonly group: Top;
readonly mergedAnnotations: Context<never>;
}) => void;
readonly predicate?: Predicate<{
readonly endpoint: Top;
readonly group: Top;
}>;
}): void

Services

Since v4.0.0

Adds additional schemas to components/schemas. The provided schemas must have a identifier annotation.

Signature

declare class AdditionalSchemas extends Shape<"effect/http-api/HttpApi/AdditionalSchemas", readonly Array<Constraint>, this> {
constructor(_: never);
}
Since v4.0.0

Schema parse options for error bodies: server encoding and client decoding. Falls back to ParseOptions when unset.

Signature

declare class ErrorParseOptions extends Shape<"effect/http-api/HttpApi/ErrorParseOptions", ParseOptions, this> {
constructor(_: never);
}
Since v4.0.0

Schema parse options for request headers and the headers of WithHeaders responses: server decoding/encoding and client encoding/decoding, including buffered and streamed responses. Falls back to ParseOptions when unset.

Signature

declare class HeadersParseOptions extends Shape<"effect/http-api/HttpApi/HeadersParseOptions", ParseOptions, this> {
constructor(_: never);
}
Since v4.0.0

Schema parse options for path params: server decoding, client encoding, and HttpApiClient.urlBuilder. Falls back to ParseOptions when unset.

Signature

declare class ParamsParseOptions extends Shape<"effect/http-api/HttpApi/ParamsParseOptions", ParseOptions, this> {
constructor(_: never);
}
Since v4.0.0

Schema parse options for server and client codecs, set on an API, group, or endpoint.

Details

Each codec slot has its own annotation:

  • ParamsParseOptions for path params
  • QueryParseOptions for the query string
  • HeadersParseOptions for request headers and WithHeaders response headers
  • PayloadParseOptions for request bodies
  • SuccessParseOptions for success bodies
  • ErrorParseOptions for error bodies

A slot annotation at any level takes precedence over ParseOptions at any level. If neither is set, Schema defaults apply. Options are replaced, not merged. For the same annotation, endpoint overrides group, which overrides API. Annotate the API before passing it to HttpApiBuilder.group or HttpApiBuilder.endpoint.

Gotchas

Header codecs receive all HTTP headers, including undeclared transport headers such as content-type, content-length, host, user-agent and proxy headers. Without HeadersParseOptions, headers use ParseOptions, so onExcessProperty: "error" rejects real requests and WithHeaders responses with transport headers.

Set HeadersParseOptions to {} at the API level to use Schema defaults for headers, even if an endpoint sets ParseOptions.

Signature

declare class ParseOptions extends Shape<"effect/http-api/HttpApi/ParseOptions", ParseOptions, this> {
constructor(_: never);
}

Example Strict bodies with default header parsing

import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint, HttpApiGroup } from "effect/http-api"
const api = HttpApi.make("Api")
.add(
HttpApiGroup.make("users").add(
HttpApiEndpoint.post("create", "/users", {
headers: { "x-api-key": Schema.String },
payload: { name: Schema.String }
})
)
)
.annotate(HttpApi.ParseOptions, { onExcessProperty: "error" })
.annotate(HttpApi.HeadersParseOptions, {})
Since v4.0.0

Schema parse options for request bodies, including multipart payloads: server decoding and client encoding. Falls back to ParseOptions when unset.

Signature

declare class PayloadParseOptions extends Shape<"effect/http-api/HttpApi/PayloadParseOptions", ParseOptions, this> {
constructor(_: never);
}
Since v4.0.0

Schema parse options for the query string: server decoding, client encoding, and HttpApiClient.urlBuilder. Falls back to ParseOptions when unset.

Signature

declare class QueryParseOptions extends Shape<"effect/http-api/HttpApi/QueryParseOptions", ParseOptions, this> {
constructor(_: never);
}
Since v4.0.0

Declares query parameters, headers and path params whose values are only sometimes secret, so they are redacted in spans without being modelled as Redacted.

Details

Names are wire names after encoding, matched like Headers.isRedactedName: strings case-insensitively, regular expressions by test. A string query name also matches the bracketed keys of a nested parameter, such as buildargs[NPM_TOKEN] for buildargs. For the endpoint's client request and server span, they extend UrlParams.CurrentRedactedNames and Headers.CurrentRedactedNames. Names from the API, its groups and its endpoints are combined. Values sent and decoded are unchanged.

params are path param names, matched exactly. On the server they become the route's redactedParams, so the server span and the HttpMiddleware.logger entry record the path with those values replaced by REDACTED. See HttpRouter.route for the requests this does not cover.

Gotchas

  • addHttpApi copies the added API's annotations onto its groups like any other annotation, so a group's own RedactedNames replaces them. Repeat the names on the group to keep both.
  • Only URL and header attributes use these names. user_agent.original and the messages of span errors are recorded as is.
  • params apply to client spans and error messages as well as server spans and HttpMiddleware.logger entries.
  • HttpApiBuilder.endpoint returns a handler without a route, so set redactedParams on the route it is mounted with.

Signature

declare class RedactedNames extends Shape<"effect/http-api/HttpApi/RedactedNames", {
readonly headers?: readonly Array<string | RegExp>;
readonly params?: readonly Array<string>;
readonly query?: readonly Array<string | RegExp>;
}, this> {
constructor(_: never);
}

Example Redacting Docker build arguments

import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint } from "effect/http-api"
const Build = HttpApiEndpoint.post("build", "/build", {
query: { buildargs: Schema.optional(Schema.Record(Schema.String, Schema.String)) },
headers: { "x-registry-config": Schema.optional(Schema.String) }
}).annotate(HttpApi.RedactedNames, {
query: ["buildargs"],
headers: ["x-registry-config"]
})
Since v4.0.0

Schema parse options for success bodies, including streams, SSE events, and the body of WithHeaders responses: server encoding and client decoding. Falls back to ParseOptions when unset.

Signature

declare class SuccessParseOptions extends Shape<"effect/http-api/HttpApi/SuccessParseOptions", ParseOptions, this> {
constructor(_: never);
}