itty-router
An ultra-tiny API microrouter, for use when size matters (e.g. Cloudflare Workers).
Features
- Tiny, with zero dependencies. Routers from ~450 bytes to a ~970 bytes batteries-included version (~240-500x smaller than Express.js).
- TypeScript. Powerfully (and flexibly) typed for any environment.
- Route-parsing & query parsing.
- Middleware. Use ours or write your own.
- 100% Test Coverage. Bulletproof for production peace-of-mind.
- Designed specifically for serverless (but works anywhere).
- No assumptions. Return anything; pass in anything.
- Future-proof. HTTP methods not-yet-invented already work with it.
Example
js
import { AutoRouter } from 'itty-router' // ~1kB
const router = AutoRouter()
router
.get('/hello/:name', ({ name }) => `Hello, ${name}!`)
.get('/json', () => [1,2,3])
.get('/promises', () => Promise.resolve('foo'))
export default router
// that's it ^-^