interface Request
extends [http.IncomingMessage]

The request a route handler receives: node's, plus the four conveniences this server attaches before dispatching.

An interface that extends IncomingMessage rather than a declare module augmenting it. The augmentation put path/query/params/send on every node:http request in the entire program — including ones this server never touched, where they were a lie the type checker would have vouched for. (It is also a global side effect JSR rejects outright.)

// Defined, not invoked: a real request comes from the server's own dispatch.
function routeOf(req: Request) {
  return `${req.path}?${new URLSearchParams(req.query)}`;
}

Properties

send: (data: string) => void

Responds with data as text/plain and ends the response.

path: string

The URL's pathname, without the query string.

query: Record<string, string>

The parsed query string.

params: Record<string, string>

Values captured by the matched route's :name segments; {} for a literal route.

Usage

import { type Request } from "lib/web/index.ts";