Creates a new HttpRouter instance.
Configuration options for the router.
Registers a single endpoint with fully typed request data inference.
The endpoint definition.
The router instance for chaining.
Groups a set of routes together.
A callback that receives a sub-router to register routes on.
The router instance for chaining.
Groups a set of routes under a path prefix.
The URL prefix for this route group (e.g. "/api/v1").
A callback that receives a sub-router to register routes on.
The router instance for chaining.
Registers one or more type-safe middleware handlers that apply to multiple routes.
Use this method for cross-cutting concerns like authentication, logging, or rate-limiting that should run across several endpoints.
For middleware that should run on only one endpoint, set the IHttpEndpoint.middlewares property directly on that endpoint definition instead — this scopes the middleware to that route alone and prevents it from affecting other endpoints.
One or more middleware registrations.
The router instance for chaining.
StaticfromAdapts a Winter TC request handler into an HttpHandlerFn that can be
used with HttpRouter.endpoint().
Winter TC handlers use the standard fetch signature
(request: Request) => Promise<Response>, while HttpRouter endpoint
handlers receive the richer HttpHandlerArgs interface. This method
bridges the two by passing args.req.webReq (the underlying Web API
Request) to the Winter TC handler and converting the returned
Response back via args.fromWebRes().
A Winter TC handler function conforming to
WinterTcRequestHandler ((request: Request) => Promise<Response>).
An HttpHandlerFn suitable for use in router.endpoint().
const winterHandler: WinterTcRequestHandler = async (request) => {
const url = new URL(request.url);
if (url.pathname === "/health") {
return new Response("OK", { status: 200 });
}
return fetch(request);
};
router.endpoint({
url: "/proxy/*",
method: ["GET"],
handler: HttpRouter.fromWinterTcHandler(winterHandler),
});