Skip to content

itty-router

Maintained
kwhitley/itty-router

An ultra-tiny API router for Cloudflare Workers and other runtimes — from ~450 bytes, with params, middleware and TypeScript.

View on GitHub
Stars
2k
Forks
84
Watchers
2k
Open issues
14

Overview

itty-router is an ultra-tiny API router designed for environments where size matters — Cloudflare Workers above all. Its routers range from roughly 450 bytes to under 1 KB for the batteries-included AutoRouter, hundreds of times smaller than Express, while still offering route parameters, query parsing, middleware, and TypeScript support.

It has been a staple of the Workers ecosystem for years and also runs anywhere that speaks the standard Request / Response APIs, including Bun, Deno, and Node.js.

Key Features

  • Tiny: ~450 B for the core router, ~1 KB for AutoRouter with built-in JSON responses and error handling
  • TypeScript-first with flexible typing for any environment
  • Route patterns with params, wildcards, and optional segments, plus query parsing
  • Middleware — use the built-ins or write your own
  • 100% test coverage
  • No assumptions: return any value, pass anything through; even future HTTP methods work

Getting Started

npm install itty-router

A complete Worker:

import { AutoRouter } from "itty-router";

const router = AutoRouter();

router
  .get("/hello/:name", ({ name }) => `Hello, ${name}!`)
  .get("/json", () => [1, 2, 3]);

export default { ...router };

AutoRouter turns returned values into proper responses and handles 404s and errors for you. Full documentation for v5 (and a v4 to v5 migration guide) is available at itty.dev.

Use Cases

  • Small, fast JSON APIs on Cloudflare Workers
  • Edge middleware and proxies where bundle size affects cold starts
  • Pairing with chanfana to add OpenAPI schemas and validation

License

MIT License.

Similar open-source projects, ranked by shared categories and tags.

All WebFramework projects →