Inline route handlers
Register one-off HTTP routes with host.http.get and HttpRouteOptions - inject maps, descriptors, and isolated routes.
Register a route with host.http.<method>(path, [options], handler). Supported methods are GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS.
The handler is an HttpRouteHandler: (ctx, scope) => HandlerResult | Promise<HandlerResult>. Omit either parameter when you do not need it.
import { FlareHost, FlareResponse } from "@flare-ts/core";import { node } from "@flare-ts/core/node";
const host = new FlareHost(node);
host.http.get("/ping", () => new FlareResponse(200, { ok: true }));
host.http.get("/users/:id", (ctx) => { return new FlareResponse(200, { id: ctx.req.rawRouteParams["id"] });});
const app = host.build();app.run();Handler scope
Section titled “Handler scope”The second argument is an HttpHandlerScope with reserved keys and your inject map entries:
| Member | Purpose |
|---|---|
scope.input | Parsed route, query, and body when the route options carry descriptor fields or a contract entry |
scope.config(Token) | Resolved config section |
scope.<name> | Services from inject: { name: Token } |
See Named inject map. Do not use input or config as inject map keys.
import { FlareHost, FlareResponse, FlareService } from "@flare-ts/core";import { node } from "@flare-ts/core/node";import { int } from "@flare-ts/lib/schema";
class DbService extends FlareService { public static override deps = []; findById(id: number) { return { id }; }}
const host = new FlareHost(node);host.scoped(DbService);
host.http.get( "/users/:id", { route: { id: int }, inject: { db: DbService } }, (_ctx, scope) => new FlareResponse(200, scope.db.findById(scope.input.route.id)),);
const app = host.build();app.run();Path rules
Section titled “Path rules”- Paths must start with
/. - Paths must not end with
/, except the lone path/is allowed. - Paths must not contain empty segments (
//); registration throws immediately. - Registering the same HTTP method twice at the same path throws at registration time.
You can register different methods at the same path. Flare merges them into one synthetic controller.
Route options
Section titled “Route options”| Option | Purpose |
|---|---|
route | Coerce named :id segments (int, str) |
query | Coerce query-string fields |
body | JSON schema, model(), or stream body marker |
response | Per-status response serializers |
maxBodyBytes | Per-route body size cap |
signedCookies | Opt into build-time check for cookies.secret |
contract | Branded httpContract entry (use this or inline fields, not both) |
inject | Named service map: { name: Token } |
state | State tokens the handler reads via ctx.state |
isolated | When true, skip global and group middleware |
name | Optional display name for logs and error targets |
Without descriptor fields, matched path segments are plain strings on ctx.req.rawRouteParams. Query keys are on ctx.req.rawQueryParams (a URLSearchParams).
Isolated routes
Section titled “Isolated routes”Set { isolated: true } when a route must bypass global and group middleware (for example a health check that must not run auth):
host.http.get("/health", { isolated: true }, () => new FlareResponse(200, { ok: true }));Inside route groups
Section titled “Inside route groups”Inside host.http.group, use g.get, g.post, and the same overloads. Paths are prefixed with the group prefix. See Route groups and versioning.
Related
Section titled “Related”- Controller classes: when to promote routes to a class
- HTTP contracts: descriptor fields and validation timing
- Routing behavior: runtime matching after
build()