@smitejs/http
HTTP semantics for Smite: apps, routes, endpoints and the serve executor.
yarn add @smitejs/http54 documented symbols · version 2.0.0-SNAPSHOT.0 · source
Aspects
functioncompose
function compose(stages: readonly ((ctx: HttpMiddlewareContext, next: () => Promise<HttpResponse>) => unknown | Promise<unknown>)[], handler: (ctx: HttpMiddlewareContext) => Promise<HttpResponse>): (ctx: HttpMiddlewareContext) => Promise<HttpResponse>;Composes pipeline stages into the core handler, left-to-right. Each stage receives ctx and a next that runs the remainder of the chain; the returned value becomes the eventual HttpResponse. Stages may be middleware or interceptors — both share the (ctx, next) shape.
packages/http/src/middleware.ts:8
functioncurrentLogger
function currentLogger(): RequestLogger | undefined;Returns the pino logger for the current request (the one created by requestLogger), or undefined when no logging aspect ran.
packages/http/src/middleware.ts:55
interfaceHttpAspect
interface HttpAspect {
readonly kind: HttpAspectKind;
readonly fn: HttpMiddleware | HttpGuard | HttpInterceptor | HttpFilter;
}A named pipeline stage registered on an app via app.use. Built with the aspect factory and stored as an http.aspect IR node on the app.
packages/http/src/aspects.ts:81
constHttpAspectKind
const HttpAspectKind: {
readonly MIDDLEWARE: "middleware";
readonly GUARD: "guard";
readonly INTERCEPTOR: "interceptor";
readonly FILTER: "filter";
};
type HttpAspectKind = (typeof HttpAspectKind)[keyof typeof HttpAspectKind];The kind of an HttpAspect: which stage of the request pipeline it runs at.
packages/http/src/aspects.ts:66
typeHttpFilter
type HttpFilter = (response: HttpResponse, ctx: HttpMiddlewareContext) => HttpResponse | Promise<HttpResponse>;A response post-processor: receives the response produced by the handler (after validation and dispatch) and returns the response that is actually served. Filters run after guards, middleware, interceptors, and the handler.
packages/http/src/aspects.ts:54
typeHttpGuard
type HttpGuard = (ctx: HttpMiddlewareContext) => HttpResponse | undefined | Promise<HttpResponse | undefined>;A request gate: returns a response to short-circuit the pipeline (a 401 for an unauthenticated call, say) or undefined/void to continue into the handler.
packages/http/src/aspects.ts:31
typeHttpInterceptor
type HttpInterceptor = (ctx: HttpMiddlewareContext, next: () => Promise<HttpResponse>) => HttpResponse | Promise<HttpResponse>;An outer wrapper around the whole pipeline: like middleware, but it always resolves the final HttpResponse, so it can observe and rewrite the response on the way out (timing, tracing headers, error mapping).
packages/http/src/aspects.ts:42
typeHttpMiddleware
type HttpMiddleware = (ctx: HttpMiddlewareContext, next: () => Promise<unknown>) => unknown | Promise<unknown>;A pipeline stage that wraps the remainder of the chain: it runs next() (or short-circuits) around the following stages and the matched route handler. The returned value is the eventual HttpResponse.
packages/http/src/aspects.ts:19
interfaceHttpMiddlewareContext
interface HttpMiddlewareContext {
readonly request: HttpRequest;
readonly scope: ScopeContext;
}The request-scoped context handed to middleware, guards, and interceptors: the raw request plus the mutable request ScopeContext carried by @smitejs/core runWithScope. Stash shared values (a logger, a tracer) on scope for the rest of the call stack to read.
packages/http/src/aspects.ts:6
functionrequestLogger
function requestLogger(options?: RequestLoggerOptions): HttpAspect;Logging aspect for incoming requests. It reads the active @smitejs/core scope, builds a request-scoped pino logger from that context via registerLogger, and logs the request and its response (status + duration). Handlers and later stages obtain the same logger with currentLogger. Apply it with app.use(requestLogger(...)).
const app = http.app().use(requestLogger({ level: "error" }));
const routes = http.router();
routes
.accept(HttpMethod.GET, "/health")
.handler((_ctx) => json({ ok: true }));
app.use(routes);
const router = app.serve();{ status: 200, body: { ok: true } }packages/http/src/middleware.ts:67
typeRequestLogger
type RequestLogger = Logger;The request-scoped pino logger populated by requestLogger. Read it anywhere inside the request through currentLogger; it carries the request context under base so logs are traceable.
packages/http/src/middleware.ts:46
interfaceRequestLoggerOptions
interface RequestLoggerOptions {
readonly level?: string;
readonly base?: Readonly<Record<string, unknown>>;
}Options for the built-in request logger aspect.
packages/http/src/middleware.ts:34
DSL
functionaccept
function accept<Base extends RouteInputConfig>(plan: {
readonly endpoints: EndpointPlan[];
}, route: HttpRouteBuilder<Base>, method: HttpMethod, path: string): HttpEndpointBuilder<Base>;Declares an endpoint (method + path) on a router plan and returns a builder for its optional per-endpoint input and its handler. input resolves per bucket against the router's input (endpoint wins, router inherits).
const app = http.app("wiki");
const routes = http.router();
routes
.accept("GET", "/pages/:slug")
.handler((ctx) => json({ slug: ctx.params.slug }));
app.use(routes);1packages/http/src/endpoint.ts:41
functionapp
function app(name?: string): HttpAppBuilder;Creates an HTTP app junction. The returned reference is the app descriptor with the DSL attached, so serve(app) takes it directly. Inject standalone route builders and aspects with use(...).
const routes = http.router();
routes.accept("GET", "/health").handler(() => json({ ok: true }));
routes
.accept("GET", "/items")
.input({ query: z.object({ q: z.string().optional() }) })
.handler((ctx) => json({ q: ctx.query.q ?? null }));
routes
.accept("GET", "/items/:id")
.input({ params: z.object({ id: z.coerce.number() }) })
.handler((ctx) => json({ id: ctx.params.id }));
routes
.accept("POST", "/items")
.input({ body: z.object({ title: z.string().min(1) }) })
.handler((ctx) => status(201).json({ title: ctx.body.title }));
app.use(routes);{ status: 200, body: { id: 42 } }interfaceEndpointPlan
interface EndpointPlan {
readonly method: HttpMethod;
readonly path: string;
req?: RouteInputConfig;
handler?: HttpHandler;
}A deferred endpoint declaration on a router plan: its method + path pair, an optional per-endpoint req override, and its handler. Materialized into an http.endpoint node (plus an http.handler child) when the router is injected into an app.
packages/http/src/endpoint.ts:9
consthttp
const http: {
app: typeof app;
router: typeof router;
methods: {
get: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
post: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
put: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
patch: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
delete: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
head: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
options: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
any: <Next extends import("./types.js").RouteInputConfig>(path: string, input: Next, handler: import("./types.js").HttpHandler<import("./types.js").MergeRequestConfig<import("./types.js").RouteInputConfig, Next>>) => import("./router.js").HttpRouteBuilder<import("./types.js").RouteInputConfig>;
};
aspect: {
middleware: (fn: import("./aspects.js").HttpMiddleware) => HttpAspect;
guard: (fn: import("./aspects.js").HttpGuard) => HttpAspect;
interceptor: (fn: import("./aspects.js").HttpInterceptor) => HttpAspect;
filter: (fn: import("./aspects.js").HttpFilter) => HttpAspect;
};
json: (body: unknown, status?: number) => import("./types.js").HttpResponse;
status: (statusCode: number) => import("./response.js").StatusBuilder;
serve: typeof serve;
serveNode: typeof serveNode;
requestLogger: typeof requestLogger;
currentLogger: typeof currentLogger;
cookies: (name: string) => import("@smitejs/fp").Extractor<import("./types.js").HttpRequest, string>;
headers: (name: string) => import("@smitejs/fp").Extractor<import("./types.js").HttpRequest, string>;
params: (name: string) => import("@smitejs/fp").Extractor<import("./types.js").HttpRequest, string>;
query: (name: string) => import("@smitejs/fp").Extractor<import("./types.js").HttpRequest, string>;
chain: typeof chain;
getExtractorMetadata: (fn: unknown) => import("@smitejs/fp").ExtractorMetadata | undefined;
};The HTTP DSL surface: app, router, methods, aspect, json, status.
const app = http.app("store");
const routes = http.router();
app.use(routes);"app"packages/http/src/index.ts:107
interfaceHttpAppBuilder
interface HttpAppBuilder extends AppDescriptor {
readonly use: (...injectables: HttpInjectable[]) => HttpAppBuilder;
readonly serve: () => HttpRouter;
}An app reference: the app IR node carrying its use and serve methods. use injects router builders and AOP aspects; pass the reference around, never reach into descriptor internals.
const app = http.app("store");
const routes = http.router();
app.use(routes);"app"interfaceHttpEndpointBuilder
interface HttpEndpointBuilder<Base extends RouteInputConfig = RouteInputConfig, Config extends RouteInputConfig = MergeRequestConfig<Base, Base>> {
readonly input: <Next extends RouteInputConfig>(config: Next) => HttpEndpointBuilder<Base, MergeRequestConfig<Base, Next>>;
readonly handler: (fn: HttpHandler<Config>) => HttpRouteBuilder<Base>;
}An endpoint reference: the plan carrying its input (the explicit inheritance of MergeRequestConfig) and handler methods. handler wires the function and returns the owning router, so declarations chain.
packages/http/src/endpoint.ts:24
interfaceHttpRouteBuilder
interface HttpRouteBuilder<Config extends RouteInputConfig = RouteInputConfig> extends HttpRouterBuilder {
readonly input: <Next extends RouteInputConfig>(config: Next) => HttpRouteBuilder<Next>;
readonly accept: (method: HttpMethod, path: string) => HttpEndpointBuilder<Config>;
readonly get: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
readonly post: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
readonly put: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
readonly patch: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
readonly delete: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
readonly head: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
readonly options: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
readonly any: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<Config, Next>>) => HttpRouteBuilder<Config>;
}A router reference: a standalone builder that declares endpoints and is injected into an app with app.use(...). Until then it is a plain plan — no IR is written. Routes created by the same builder share a router-level input that each endpoint inherits per bucket.
const app = http.app("store");
const routes = http.router();
routes.get(
"/users/:id",
{ params: z.object({ id: z.string() }) },
(ctx) => json({ id: ctx.params.id }),
);
routes.post("/users", { body: z.object({ name: z.string() }) }, (ctx) =>
status(201).json({ name: ctx.body.name }),
);
app.use(routes);
const health = methods.get("/health", {}, () => json({ ok: true }));
app.use(health);2
2packages/http/src/router.ts:66
interfaceHttpRouterBuilder
interface HttpRouterBuilder {
readonly [routeBuilderSymbol]: typeof routeBuilderSymbol;
}The type-level shape of any route builder, regardless of its inferred input config. app.use accepts this plus HttpAspect so routes can be declared standalone and injected later.
packages/http/src/router.ts:55
functionmaterializeRoute
function materializeRoute<Config extends RouteInputConfig>(app: AppDescriptor, builder: HttpRouterBuilder): RouteDescriptor<Config>;Materializes an injected router builder into an app's IR: creates the http.route node (keyed within the app, auto-numbered when unnamed), its http.endpoint children, and each endpoint's http.handler. Called by app.use(...).
packages/http/src/router.ts:302
constmethods
const methods: {
get: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
post: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
put: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
patch: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
delete: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
head: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
options: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
any: <Next extends RouteInputConfig>(path: string, input: Next, handler: HttpHandler<MergeRequestConfig<RouteInputConfig, Next>>) => HttpRouteBuilder<RouteInputConfig>;
};A standalone, single-endpoint router builder per HTTP method. methods.get is sugar for router().accept("GET", path).input(config).handler(fn); inject the result with app.use(...).
const app = http.app("store");
const routes = http.router();
routes.get(
"/users/:id",
{ params: z.object({ id: z.string() }) },
(ctx) => json({ id: ctx.params.id }),
);
routes.post("/users", { body: z.object({ name: z.string() }) }, (ctx) =>
status(201).json({ name: ctx.body.name }),
);
app.use(routes);
const health = methods.get("/health", {}, () => json({ ok: true }));
app.use(health);2
2packages/http/src/router.ts:227
functionrouter
function router<Config extends RouteInputConfig = RouteInputConfig>(config?: RouteConfig): HttpRouteBuilder<Config>;Creates a router builder that is not yet attached to an app. Declare endpoints on it (with accept, method shortcuts, or via methods) and inject it with app.use(builder). Pass config (name, summary, description) for artifact generators.
const app = http.app("wiki");
const routes = http.router().input({
query: z.object({ language: z.string() }).partial(),
params: z.object({ slug: z.string() }),
});
app.use(routes);1packages/http/src/router.ts:133
Executor
constmergeRequestConfig
const mergeRequestConfig: (base: RouteInputConfig | undefined, override: RouteInputConfig | undefined) => RouteInputConfig | undefined;Resolves the effective request config for an endpoint by per-bucket inheritance: the endpoint's req wins when it declares a bucket, otherwise the router-level req provides it. Returns undefined when neither declares anything.
packages/http/src/request-config.ts:6
functionserve
function serve(app: AppDescriptor, options?: ServeOptions): HttpRouter;Turns an app descriptor into a runtime request handler. Walks the IR via child refs, never the registry, and finalizes (deep-freezes) the graph before dispatching. Each request runs inside an AsyncLocalStorage scope so aspects and handlers can observe request context. Pipeline order follows registration: interceptors/middleware wrap, guards gate, the matched handler runs, then response filters post-process.
const app = http.app("store");
const routes = http.router();
routes.accept("GET", "/health").handler(() => json({ ok: true }));
app.use(routes);
const router = serve(app);
const response = await router({
method: "GET",
path: "/health",
query: {},
headers: {},
cookies: {},
params: {},
body: undefined,
});{ status: 200, body: { ok: true } }packages/http/src/serve.ts:169
interfaceServeOptions
interface ServeOptions {
readonly routers?: readonly string[];
}Options for serve: scope the router to a subset of the app's named routers.
packages/http/src/serve.ts:104
Extraction
constcookies
const cookies: (name: string) => Extractor<HttpRequest, string>;Reads a cookie value from the request, returning none when absent.
const resolve = (request: HttpRequest) =>
http
.chain(
cookies("session_id"),
headers("x-session-id"),
)(request)
.unwrapOr("anonymous");"abc123"
"cookie-id"packages/http/src/extract.ts:35
constheaders
const headers: (name: string) => Extractor<HttpRequest, string>;Reads a header value from the request, returning none when absent.
const resolve = (request: HttpRequest) =>
http
.chain(
cookies("session_id"),
headers("x-session-id"),
)(request)
.unwrapOr("anonymous");"abc123"
"cookie-id"packages/http/src/extract.ts:46
constparams
const params: (name: string) => Extractor<HttpRequest, string>;Reads a path parameter from the request, returning none when absent.
const resolve = (request: HttpRequest) =>
http
.chain(
cookies("session_id"),
headers("x-session-id"),
)(request)
.unwrapOr("anonymous");"abc123"
"cookie-id"packages/http/src/extract.ts:64
constquery
const query: (name: string) => Extractor<HttpRequest, string>;Reads a query parameter from the request, returning none when absent.
const resolve = (request: HttpRequest) =>
http
.chain(
cookies("session_id"),
headers("x-session-id"),
)(request)
.unwrapOr("anonymous");"abc123"
"cookie-id"packages/http/src/extract.ts:75
Node server
interfaceNodeServerDocs
interface NodeServerDocs {
readonly router: HttpRouter;
readonly paths: readonly string[];
}A router mounted at one or more exact paths, served ahead of the app's own routes. Use it for documentation or admin endpoints that must not collide with app routes.
packages/http/src/node-server.ts:8
interfaceNodeServerOptions
interface NodeServerOptions {
readonly docs?: NodeServerDocs;
readonly transformRequest?: (req: IncomingMessage, parsed: HttpRequest) => Partial<HttpRequest> | Promise<Partial<HttpRequest>>;
}Options for serveNode.
packages/http/src/node-server.ts:22
functionserveNode
function serveNode(app: AppDescriptor, options?: NodeServerOptions): Server;Turns an app into a node:http server. Parses the request into an HttpRequest, dispatches through serve(app) (with any mounted docs routers checked first), and writes the response. The returned server is not yet listening, so callers compose .listen(port, host, onListen).
const app = http.app("store");
const route = http.router();
route.accept("GET", "/health").handler(() => json({ ok: true }));
app.use(route);
const server = serveNode(app);200
{ ok: true }packages/http/src/node-server.ts:95
Reference
functionaddAspect
function addAspect(app: AppDescriptor, entry: HttpAspect): HttpAspectDescriptor;Registers an aspect as an http.aspect child of an app. @group Aspects
packages/http/src/aspects.ts:122
constaspect
const aspect: {
middleware: (fn: HttpMiddleware) => HttpAspect;
guard: (fn: HttpGuard) => HttpAspect;
interceptor: (fn: HttpInterceptor) => HttpAspect;
filter: (fn: HttpFilter) => HttpAspect;
};Aspect factory: labels plain functions as pipeline stages. @group Aspects
const app = http.app("secure");
app.use(
aspect.middleware(async (ctx, next) => {
ctx.scope.clock = { started: Date.now() };
return next();
}),
);
app.use(
aspect.guard((ctx) =>
ctx.request.headers.authorization
? undefined
: status(401).json({ error: "unauthorized" }),
),
);
app.use(
aspect.interceptor(async (_ctx, next) => {
const response = await next();
return status(response.status)
.header("x-powered-by", "smite")
.json(response.body);
}),
);
app.use(
aspect.filter((response) =>
status(response.status).json({
...(response.body as Record<string, unknown>),
served: true,
}),
),
);
const routes = http.router();
routes.accept(HttpMethod.GET, "/me").handler(() => json({ user: "self" }));
app.use(routes);{
status: 200,
body: { user: "self", served: true },
headers: { "x-powered-by": "smite" },
}
{
status: 401,
body: { error: "unauthorized" },
headers: { "x-powered-by": "smite" },
}packages/http/src/aspects.ts:99
functionaspectsOf
function aspectsOf(app: AppDescriptor): readonly HttpAspect[];The aspects registered on an app, in order. @group Aspects
packages/http/src/aspects.ts:136
interfaceHandlerDescriptor
interface HandlerDescriptor extends Descriptor<"http.handler", {
readonly fn: HttpHandler;
}> {
}A handler node wrapping a runtime function, related to its endpoint.
packages/http/src/router.ts:35
interfaceHttpAspectDescriptor
interface HttpAspectDescriptor extends Descriptor<"http.aspect", {
readonly kind: HttpAspectKind;
readonly fn: HttpAspect["fn"];
}> {
}A request pipeline stage: (ctx, next) => response. @group Aspects
packages/http/src/aspects.ts:92
typeHttpInjectable
type HttpInjectable = HttpAspect | HttpRouterBuilder;Anything app.use accepts: an AOP aspect or an injectable route builder. @group DSL
typeHttpRouter
type HttpRouter = (request: HttpRequest) => Promise<HttpResponse>;Runtime request handler produced by serve. @group Executor
constrouteBuilderSymbol
const routeBuilderSymbol: unique symbol;Type-level tag carried by every HttpRouteBuilder.
packages/http/src/router.ts:52
interfaceRouteDescriptor
interface RouteDescriptor<Config extends RouteInputConfig = RouteInputConfig> extends Descriptor<"http.route", {
readonly name?: string;
readonly summary?: string;
readonly description?: string;
readonly req?: Config;
}> {
}A route node in the IR, holding its descriptive config and req. @group DSL
packages/http/src/router.ts:39
constwithMethods
const withMethods: <Target extends object, M extends Methods>(target: Target, methods: M) => Target & M;Attaches builder methods to a descriptor as non-enumerable properties, so the descriptor still reads as a plain IR node (Object.keys sees only __kind/__key/data) while carrying its reference-based builder surface.
packages/http/src/withMethods.ts:3
Responses
constjson
const json: (body: unknown, status?: number) => HttpResponse;Builds a response with the given body and status (default 200).
const ok = json({ ok: true });
const created = status(201).json({ id: "42" });{ status: 200, body: { ok: true } }
{ status: 201, body: { id: "42" } }packages/http/src/response.ts:3
conststatus
const status: (statusCode: number) => StatusBuilder;Builds a response for a fixed status code, optionally accumulating headers before calling .json(body).
const ok = json({ ok: true });
const created = status(201).json({ id: "42" });{ status: 200, body: { ok: true } }
{ status: 201, body: { id: "42" } }packages/http/src/response.ts:27
interfaceStatusBuilder
interface StatusBuilder {
header: (name: string, value: string) => StatusBuilder;
json: (body: unknown) => HttpResponse;
}A mutable, chainable status builder. header accumulates response headers; json snapshots them into the final HttpResponse.
packages/http/src/response.ts:14
Routes
interfaceCollectedEndpoint
interface CollectedEndpoint {
readonly method: HttpMethod;
readonly path: string;
readonly pathParams: readonly string[];
}
interface CollectedEndpoint {
readonly method: HttpMethod;
readonly path: string;
readonly pathParams: readonly string[];
readonly req?: RouteInputConfig;
}An endpoint as seen by artifact generators: method, path template, and the params extracted from the template.
interfaceCollectedEndpoint
interface CollectedEndpoint {
readonly method: HttpMethod;
readonly path: string;
readonly pathParams: readonly string[];
}
interface CollectedEndpoint {
readonly method: HttpMethod;
readonly path: string;
readonly pathParams: readonly string[];
readonly req?: RouteInputConfig;
}An endpoint as seen by artifact generators: its method, path template, the params extracted from the template, and its optional per-endpoint req override.
packages/http/src/routes.ts:32
interfaceCollectedRoute
interface CollectedRoute {
readonly name?: string;
readonly summary?: string;
readonly description?: string;
readonly req?: RouteInputConfig;
readonly endpoints: readonly CollectedEndpoint[];
}A route as seen by artifact generators: its descriptive config (name, summary, description), the router-level req base, plus the endpoints declared on it.
packages/http/src/routes.ts:17
functionroutesOf
function routesOf(app: AppDescriptor): readonly CollectedRoute[];Walks an app's http.route and http.endpoint children and returns the collected routes with their endpoints and path params. Shared by the client and OpenAPI artifact generators.
const app = http.app("store");
const route = http.router().input({
query: z.object({ q: z.string().optional() }).partial(),
});
route
.accept("GET", "/users/:id")
.handler((ctx) => json({ id: ctx.params.id }));
app.use(route);
const collected = routesOf(app);1
["id"]packages/http/src/routes.ts:70
Types
constHttpMethod
const HttpMethod: {
readonly ANY: "ANY";
readonly GET: "GET";
readonly POST: "POST";
readonly PUT: "PUT";
readonly DELETE: "DELETE";
readonly OPTIONS: "OPTIONS";
readonly HEAD: "HEAD";
readonly PATCH: "PATCH";
};
type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod];The HTTP methods supported by the DSL.
constHttpStatus
const HttpStatus: {
readonly OK: 200;
readonly CREATED: 201;
readonly BAD_REQUEST: 400;
readonly NOT_FOUND: 404;
readonly INTERNAL_SERVER_ERROR: 500;
};
type HttpStatus = (typeof HttpStatus)[keyof typeof HttpStatus];A subset of HTTP status codes used by the response helpers.
typeMergeRequestConfig
type MergeRequestConfig<Base extends RouteInputConfig, Next extends RouteInputConfig> = Partial<{
readonly query: [
Next["query"]
] extends [
z.ZodType
] ? Next["query"] : [
Base["query"]
] extends [
z.ZodType
] ? Base["query"] : never;
readonly params: [
Next["params"]
] extends [
z.ZodType
] ? Next["params"] : [
Base["params"]
] extends [
z.ZodType
] ? Base["params"] : never;
readonly headers: [
Next["headers"]
] extends [
z.ZodType
] ? Next["headers"] : [
Base["headers"]
] extends [
z.ZodType
] ? Base["headers"] : never;
readonly body: [
Next["body"]
] extends [
z.ZodType
] ? Next["body"] : [
Base["body"]
] extends [
z.ZodType
] ? Base["body"] : never;
}>;The explicit-inheritance request config of an endpoint: for each bucket, the endpoint's req wins when present and the router-level req is the fallback. Buckets the endpoint does not declare stay inherited from the router.
interfaceRouteConfig
interface RouteConfig {
readonly name?: string;
readonly summary?: string;
readonly description?: string;
}Declarative configuration attached to a route and stored on its IR node. Purely descriptive; consumed by artifact generators such as the OpenAPI plugin.