@reharis/http-router
v0.1.0
Published
A minimal http router for modern javascript runtimes.
Downloads
69
Readme
@reharis/http-router
A minimal http router for modern javascript runtimes.
import { router } from "@reharis/http-router";
const app = router();
app.get("/", () => new Response("Hello"));
app.get("/users/:id", async ({ params }) => {
const user = await findUser(params.id);
return user ? Response.json(user) : new Response("Not Found", { status: 404 });
});
export default app;The router supports exact paths and named path segments. Query strings do not participate in matching, and route parameters are decoded strings. Static segments take precedence over named segments; ties use registration order. Registering the same decoded method and path twice throws.
Handlers receive a frozen context containing the request and frozen parameters. A handler must
return a Response or a promise of one. Unmatched requests return 404 Not Found, and handler
errors are propagated unchanged.
Supported methods are GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS.
