Askr documentation
Generated API snapshot

@askrjs/server/router

Exports from the declarations published in @askrjs/server. Signatures reflect the published artifact.

Exports

This entrypoint publishes 9 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.

ApiRoutetype

ApiRoute: any

A single registered route: a path/method pattern paired with a handler (or WebSocket upgrade handler).

path
path: string;
method
method?: string | readonly string[];
handler
handler: Handler<RouteParams>;
upgrade
upgrade?: WebSocketHandler<RouteParams>;

ApiRouteOptionstype

ApiRouteOptions: any

Per-route configuration shared by {@link ApiRoute}.

auth
auth?: AuthRequirement;
middleware
middleware?: readonly Middleware<RouteParams>[];
maxRequestBytes
maxRequestBytes?: number;

createRoutertype

createRouter: () => Router

Creates an empty, mutable {@link Router} with chainable HTTP-method route builders (`get`, `post`, `put`, `patch`, `delete`, `options`, `head`, `trace`, `connect`, `ws`) and a `use` method for registering middleware.

defineRoutestype

defineRoutes: (definition: (route: RouteBuilder) => void) => ApiRoute[]

Builds a flat list of {@link ApiRoute}s by invoking `definition` with a {@link RouteBuilder}. Useful for defining a set of routes without a full {@link Router} (e.g. to compose into one).

Handlertype

Handler: {
  bivarianceHack(context: ServerContext<RouteParams>): Response | Promise<Response>;
}["bivarianceHack"]

A route handler function that produces a response for a given {@link ServerContext}.

Middlewaretype

Middleware: {
  bivarianceHack(context: ServerContext<RouteParams>, next: Next): Response | Promise<Response>;
}["bivarianceHack"]

A middleware function that may short-circuit or delegate to `next` to produce a response.

RouteBuildertype

RouteBuilder: any

Chainable, per-HTTP-method route registration methods, one per method plus `ws` for WebSockets.

route
route<const Path extends string>(method: string | readonly string[], path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
get
get<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
post
post<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
put
put<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
patch
patch<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
delete
delete<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
options
options<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
head
head<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
trace
trace<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
connect
connect<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;
ws
ws<const Path extends string>(path: Path, handler: WebSocketHandler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): ApiRoute<PathParams<Path>>;

Routertype

Router: any

A mutable collection of routes and middleware, built with chainable per-method registration methods (each returning the router itself for chaining) and a `use` method for middleware.

routes
readonly routes: readonly ApiRoute[];
middleware
readonly middleware: readonly Middleware[];
use
use(...middleware: Middleware[]): Router;
route
route<const Path extends string>(method: string | readonly string[], path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
get
get<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
post
post<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
put
put<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
patch
patch<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
delete
delete<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
options
options<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
head
head<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
trace
trace<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
connect
connect<const Path extends string>(path: Path, handler: Handler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;
ws
ws<const Path extends string>(path: Path, handler: WebSocketHandler<PathParams<Path>>, options?: ApiRouteOptions<PathParams<Path>>): Router;

WebSocketHandlertype

WebSocketHandler: {
  bivarianceHack(socket: WebSocketLike, context: ServerContext<RouteParams>): void | Promise<void>;
}["bivarianceHack"]

Handler invoked with a live {@link WebSocketLike} once a connection has been upgraded.