-
Notifications
You must be signed in to change notification settings - Fork 2
Quick Start
Nadhi-(Kushi) edited this page Apr 1, 2026
·
2 revisions
import { createApp } from "@http-native/core";
const app = createApp();
app.get("/", (req, res) => {
res.send("Hello from http-native");
});
const server = await app.listen().port(3000);
console.log(server.url);app.get("/users/:id", (req, res) => {
res.json({
id: req.params.id,
q: req.query.q ?? null,
agent: req.header("user-agent") ?? null,
});
});req.body is the raw Buffer | null. If you expect JSON, parse it with req.json():
app.post("/users", (req, res) => {
const body = req.json() ?? {};
res.status(201).json(body);
});app.get("/text", (req, res) => {
res.send("plain text");
});
app.get("/json", (req, res) => {
res.json({ ok: true });
});
app.get("/html", (req, res) => {
res.html("<html><body><h1>Hello</h1></body></html>");
});Use app.static() when the HTML is known up front and you want the native exact-route fast path:
app.static("/about", "<html><body><h1>About</h1></body></html>");You can also inject SSR data into window.hnSSR.objects:
app.static("/dashboard", "<html><body><div id=\"app\"></div></body></html>", {
objects: {
user: { id: 1, name: "Alice" },
},
});For self-starting apps:
const app = createApp().reload({
files: ["src", "routes"],
debounceMs: 80,
clear: true,
});
await app.listen().port(3000).hot();Or use the CLI:
http-native dev ./server.ts --port 3000Http-native is open to everyone, but we have strict regulations and licensing fees for large organizations