Skip to content

RouterRoute

reference
1 min readUpdated

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

PropertyType
basePathstring
pathstring
methodstring
handlerH

Diagram

mermaid
graph 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

ts
interface 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 basePath and path separate so the router can compose the final route path.
  • Match method values to the format expected by the router, such as "GET" or "POST".
  • Type handler with the handler signature used by the router implementation.
  • Preserve the generic H type when passing routes through registration or matching code.

Was this page helpful?

Download as PDF
RouterRoute — Hono (narrator proof)