Kind: Interface
Source: src/types.ts
RouterRoute describes a route registered with a router. It stores the route's base path, path, HTTP method, and handler so the router can match requests and invoke the associated handler.
Properties
| Property | Type |
|---|---|
basePath | string |
path | string |
method | string |
handler | H |
Diagram
mermaidgraph LR Router[Router] --> Route[RouterRoute] Route --> BasePath[basePath: string] Route --> Path[path: string] Route --> Method[method: string] Route --> Handler[handler: H] Request[Incoming request] --> Router Router --> Handler
Usage
tsinterface RouterRoute<H> {
basePath: string;
path: string;
method: string;
handler: H;
}
type RequestHandler = (request: Request) => Response;
const getUserRoute: RouterRoute<RequestHandler> = {
basePath: "/api",
path: "/users/:id",
method: "GET",
handler: (request) => {
return new Response(`Requested: ${request.url}`);
},
};
AI Coding Instructions
- Keep
basePathandpathseparate so the router can compose the final route path. - Match
methodvalues to the format expected by the router, such as"GET"or"POST". - Type
handlerwith the handler signature used by the router implementation. - Preserve the generic
Htype when passing routes through registration or matching code.
Was this page helpful?