Skip to content

Quick Start

Nadhi-(Kushi) edited this page Apr 1, 2026 · 2 revisions

Quick Start

Create An App

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);

Read Request Data

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);
});

Send Responses

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>");
});

Static HTML Fast Path

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" },
  },
});

Dev Reload

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 3000

Clone this wiki locally