Zen Router
An opinionated HTTP router with typed path params, built-in body validation, and a clean auth model.
Zen Router is an opinionated API router built by Liveblocks, where it has been powering billions of requests per month. It’s designed for Cloudflare Workers, Bun, Node.js, and other modern JavaScript runtimes.
npm install @liveblocks/zenrouterQuick example
importfrom "@liveblocks/zenrouter";
importfrom "zod";
const zen = new ZenRouter
authorize: asyncreq=>
const token =get"Authorization"
const currentUser = awaitgetUserByToken
if!currentUser) return false;
return
});
// Get a specific post
zen.route
"GET /api/posts/<postId>",
asyncp, auth=>
const post = awaitgetPost
return
// Create a new post for the current user
zen.route
"POST /api/posts",
z.objectstring
asyncauth, body=>
const post = awaitcreatePost
return
export defaultFeatures
- Type-safe everywhere. Your handler receives
{ p, q, body }, all fully typed. - Body validation. With any Standard Schema compatible library.
- Authorization. Mandatory by design, opt-out for public routes.
- Composing routers. Isolate routers by auth strategy with
ZenRelay. - CORS. Built-in, not bolted on.
- Error handling.
abort(404)from any handler, customizable error shapes. - Response helpers.
json(),html(),textStream(), and more. - OpenTelemetry. Automatic span attributes for matched routes.
- Runs anywhere. Cloudflare Workers, Bun, Node.js, and any runtime with Web
Request/Response.