DEV Community

Naxrul Ahmed
Naxrul Ahmed

Posted on

xanout

A tiny, lightweight router built on the Web-standard Request and Response APIs.

Website · npm · Documentation


Features

  • Lightweight — Minimal footprint with just one dependency.
  • Web Standards — Built around native Request, Response, and Headers.
  • Middleware — Flexible middleware with next() support.
  • Sub-routers — Mount routers with path prefixes.
  • Request Context — Access request-scoped context from anywhere.
  • Cookies — Built-in cookie management and serialization.
  • Static Files — Serve static assets with caching support.
  • Framework Adapters — Integrate with Express, Fastify, Koa, Hono, and more.
  • Multi-runtime — Node.js, Bun, Deno, and Cloudflare Workers (nodejs_compat).

Installation

npm install xanout
Enter fullscreen mode Exit fullscreen mode

Quick Start

import { Router } from "xanout";

const route = Router();

// Middleware
route.use((next) => {
  console.log("Request received");
  return next();
});

// Routes
route.get("/", () => {
  return new Response("Hello World");
});

route.get("/users/:id", () => {
  const { params } = route.context();

  return Response.json({ id: params.id });
});

// Handle requests
const response = await route.fetch(
  new Request("http://localhost/users/42")
);
Enter fullscreen mode Exit fullscreen mode

Documentation

Explore the documentation for installation guides, API references, middleware, adapters, examples, and advanced usage.

Read the Documentation →

License

MIT

Top comments (0)