Introduction
Introduction
Introduction
chttp is a minimal async-first HTTP router for node:http, authored inside the scriptc compilable subset so the same source compiles to a native ELF.
import { createRouter } from "@chttp/router";
const app = createRouter();
app.get("/", (c) => c.text("hi"));
app.get("/user/:id", (c) => c.json({ id: c.req.param("id") }));
app.post("/echo", (c) => c.text(c.req.body()));
app.get("/slow", async (c) => {
const user = await fetchUser(c.req.param("id"));
return c.json(user);
});
app.notFound((c) => c.status(404).text("not found"));
app.serve({ port: 3000 });
Handlers and middleware may be async; dispatch settles a Promise return under the same error path as sync code, and sync handlers complete without scheduling a microtask.
Install
npm
pnpm
bun
npm i @chttp/router
pnpm add @chttp/router
bun add @chttp/router
Next: Routing. For request validation see Validation. For the bundler and native-compile pipeline see Route lowering plugin.