Install + your first endpoint
Two minutes from empty directory to a running HTTP server with typed routes, OpenAPI, and graceful shutdown.
1. Install
bash
mkdir hello-nwire && cd hello-nwire
pnpm init
pnpm add @nwire/http @nwire/endpoint zod
pnpm add -D typescript tsx @types/node2. Write the endpoint
ts
// src/main.ts
import { httpInterface, endpoint } from "@nwire/http"
import { z } from "zod"
const api = httpInterface()
api.get("/hello", () => ({ message: "hello world" }))
api.post(
"/greet",
{ input: z.object({ name: z.string() }) },
({ input }) => ({ message: `hello, ${input.name}` }),
)
await endpoint("hello", { port: 3000 }).serve(api).run()3. Run
bash
pnpm tsx src/main.tsYou should see:
▸ hello ready in 18ms
http http://localhost:3000
docs http://localhost:3000/docs
openapi http://localhost:3000/openapi.json4. Try it
bash
curl http://localhost:3000/hello
# {"message":"hello world"}
curl -X POST http://localhost:3000/greet \
-H 'Content-Type: application/json' \
-d '{"name":"Avi"}'
# {"message":"hello, Avi"}
# Visit http://localhost:3000/docs for the live OpenAPI viewer.What you got
- Typed routes — the
inputschema produces a 400 with field-level errors when you POST{}. - OpenAPI 3.1 at
/openapi.json, generated from the running config (no codegen). - Scalar docs UI at
/docs, served from the CDN. - Graceful shutdown — press
Ctrl-Cand the process finishes in-flight requests before exiting.
Next
- Add DI: L2 — + Container
- Add a plugin lifecycle: L3 — + App
- Add actors / events / projections / workflows: L4 — + Forge