Routing
Routing
Routing
Routes are registered per method: app.get | post | put | delete | patch | head | options(path, h), plus app.all(path, h) for any method and app.on(method, path, h) for custom ones.
Paths support static segments, :param, and a tail * wildcard.
app.get("/user/:id", (c) => c.req.param("id")); // literal-typed: 'id'
app.get("/wild/*", (c) => c.req.param("*"));
Semantics
- Params are percent-decoded and typed from the path literal (
ParamKey<P>). Param-less paths degradeparam()tostring | null. HEADrequests fall back to theGEThandler; node suppresses the body.- Matched path, unknown method:
405with anAllowheader built from the route’s method table. - Unmatched path:
404(customizable viaapp.notFound). - Duplicate exact
method+path: first registered wins. Match is strict: no trailing-slash normalization.
Sub-routers
const api = createRouter();
api.get("/users", handler);
app.route("/api", api);
Parent and sub middleware merge.
Next: Middleware.