-
Notifications
You must be signed in to change notification settings - Fork 2
Routing
Nadhi-(Kushi) edited this page Apr 1, 2026
·
2 revisions
Http-native uses an Express-style API over a native Rust router.
import { createApp } from "@http-native/core";
const app = createApp();
app.get("/", (req, res) => {
res.send("Home");
});
app.post("/users", (req, res) => {
res.status(201).json({ created: true });
});
app.put("/users/:id", (req, res) => {
res.json({ updated: req.params.id });
});
app.delete("/users/:id", (req, res) => {
res.sendStatus(204);
});app.get("/users/:id", (req, res) => {
res.json({ id: req.params.id });
});
app.get("/posts/:postId/comments/:commentId", (req, res) => {
res.json(req.params);
});app.get("/search", (req, res) => {
res.json({
q: req.query.q ?? null,
limit: req.query.limit ?? null,
});
});app.group("/api/v1", (api) => {
api.get("/users", listUsers);
api.post("/users", createUser);
api.get("/users/:id", getUser);
});app.use(async (req, res, next) => {
await next();
});
app.use("/api", async (req, res, next) => {
await next();
});app.all(path, handler) registers one handler for all HTTP methods on that exact route path.
app.all("/health", (req, res) => {
res.json({ method: req.method });
});app.static() registers an exact GET HTML route:
app.static("/about", "<html><body><h1>About</h1></body></html>");This is separate from normal route handlers and is meant for the native exact static fast path.
- exact paths are the cheap path
- param routes compile with named params
-
app.static()only supports exact paths without params
Http-native is open to everyone, but we have strict regulations and licensing fees for large organizations