A fetch-native, type-safe HTTP router for JavaScript/TypeScript with explicit middleware composition and zero runtime dependencies.
import { p, Wooter } from "@bronti/wooter"
const app = new Wooter()
.use(cors)
.use(auth)
.route(p.path("users", p.param("id", p.num)), "GET", async ({ params, resp }) => {
resp(Response.json({ userId: params.get("id") }))
})
export default app.fetchWooter is built on a single principle: every request must produce a response before the lifecycle completes.
This invariant ensures predictable behavior. Combined with explicit middleware composition, it makes data flow visible and error handling straightforward.
Learn more: Wooter Philosophy
- ✅ Type-Safe by Default — Full TypeScript inference for routes, middleware, and parameters
- ✅ Fetch-Native — Works with Deno, Node.js, Bun, Cloudflare Workers, and any Fetch API runtime
- ✅ Explicit Design — No hidden behavior; response propagation is clear and intentional
- ✅ Composable Middleware — State accumulates through middleware chains with type preservation
- ✅ Lightweight — Zero runtime dependencies; ~5KB gzipped
- ✅ Flexible Error Handling — Use exceptions, Result types, or custom patterns
- ✅ Zero Magic — Understand exactly what your code does
# Deno
deno add @bronti/wooter
# or via jsr
npx jsr add @bronti/wooterimport { p, Wooter } from "@bronti/wooter"
const app = new Wooter()
// GET /hello
app.route(p.path("hello"), "GET", ({ resp }) => {
resp(new Response("Hello, Wooter!"))
})
// GET /users/{id}
app.route(p.path("users", p.param("id", p.num)), "GET", ({ params, resp }) => {
resp(Response.json({ id: params.get("id") }))
})
// POST /users
app.route(p.path("users"), "POST", ({ request, resp }) => {
resp(new Response("Created", { status: 201 }))
})
export default app.fetchdeno serve app.tsEvery request must produce a response. This is Wooter's core guarantee.
app.route(p.path("example"), "GET", ({ resp }) => {
// ✅ This works
resp(new Response("OK"))
// ❌ Forgetting resp() throws HandlerDidntRespondError
})Middleware accumulates state for downstream handlers:
const app = new Wooter()
.use(async ({ next }) => {
// Add user to state
await next({ user: { id: 1, name: "Alice" } })
})
.use(async ({ state: { user }, next }) => {
// Access user from previous middleware
await next({
permissions: getPermissions(user),
})
})
.route(p.path("admin"), "GET", async ({ state, resp }) => {
// Access all accumulated state
resp(Response.json({ user: state.user, perms: state.permissions }))
})Middleware chooses how to handle responses:
// forward() — Pass through without modification
await forward({ userId: 123 })
// next() — Inspect or modify response
const response = await next({ userId: 123 })
resp(modifyHeaders(response))
// tryNext() — Capture errors as Result
const result = await tryNext()
result.match(
(response) => resp(response),
(error) => resp(new Response("Error", { status: 500 })),
)- Getting Started — 5-minute setup
- Installation — JSR, npm, Bun, esm.sh
- Core Concepts — Response-first lifecycle
- Routing — Type-safe paths and parameters
- Middleware — Building middleware chains
- Control Flow — next(), forward(), tryNext()
- API Reference — Complete API documentation
- Examples — Practical code examples
- FAQ — Common questions
import { middleware, p, Wooter } from "@bronti/wooter"
const db = new Map()
const app = new Wooter()
.route(p.path("items"), {
GET: async ({ resp }) => {
resp(Response.json(Array.from(db.values())))
},
POST: async ({ request, resp }) => {
const item = await request.json()
db.set(item.id, item)
resp(Response.json(item), { status: 201 })
},
})
.route(p.path("items", p.param("id", p.num)), {
GET: async ({ params, resp }) => {
const item = db.get(params.get("id"))
resp(item ? Response.json(item) : new Response("Not found", { status: 404 }))
},
PUT: async ({ params, request, resp }) => {
const item = await request.json()
db.set(params.get("id"), item)
resp(Response.json(item))
},
DELETE: async ({ params, resp }) => {
db.delete(params.get("id"))
resp(null, { status: 204 })
},
})
export default app.fetch// Authentication
const auth = middleware<{ user: User }>(
async ({ request, next, resp }) => {
const token = request.headers.get("Authorization")
if (!token) return resp(new Response("Unauthorized", { status: 401 }))
const user = verifyToken(token)
await next({ user })
},
)
// JSON parsing
const json = middleware<{ json: () => Promise<any> }>(
async ({ request, forward, resp, safeExit }) => {
let cached: any
await forward({
json: async () => {
if (cached) return cached
try {
return cached = await request.json()
} catch {
resp(new Response("Invalid JSON", { status: 400 }))
safeExit()
}
},
})
},
)
const app = new Wooter()
.use(json)
.use(auth)
.route(p.path("users"), "POST", async ({ state: { json }, resp }) => {
const body = await json()
resp(Response.json(body), { status: 201 })
})Wooter works with any Fetch API-compatible runtime:
| Runtime | Version | Status |
|---|---|---|
| Deno | 1.20+ | ✅ Fully supported |
| Node.js | 18+ | ✅ Fully supported |
| Bun | 0.1.0+ | ✅ Fully supported |
| Cloudflare Workers | Any | ✅ Fully supported |
| Deno Deploy | Any | ✅ Fully supported |
| Fastly Compute | Any | ✅ Fully supported |
| Modern Browsers | - | ✅ Supported (limited use cases) |
Wooter follows epoch semver. The core API is stable, but the library hasn't reached v100 yet. Consider it production-ready for non-critical applications.
| Aspect | Status |
|---|---|
| Core Routing | ✅ Stable |
| Middleware | ✅ Stable |
| API Surface | ✅ Stable |
| Public Release | In progress (aiming for v100) |
Contributions are welcome! Areas for improvement:
- Documentation and examples
- Performance optimizations
- Bug reports and fixes
- Feature ideas (with discussion first)
- Community middleware
MIT
- Full Documentation — Complete guides and references
- PHILOSOPHY.MD — Design principles and rationale
- Examples Directory — Real-world code examples
- JSR Package — Package details and usage
- Path API — Built-in typed path matching and parameter parsing