Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
itty-router
Advanced tools
Tiny, zero-dependency API router - built for Cloudflare Workers, but works everywhere!
Itty aims to be the world's smallest (~440 bytes), feature-rich JavaScript router, enabling beautiful API code with a near-zero bundlesize. Designed originally for Cloudflare Workers, itty can be used in browsers, Service Workers, edge functions, or standalone runtimes like Node, Bun, etc.!
Complete docs/API are available at itty.dev, or join our Discord channel to chat!
npm install itty-router@next
import {
error, // creates error responses
json, // creates json responses
Router, // the ~440 byte router itself
withParams, // middleware: puts params directly on the Request
} from 'itty-router'
const router = Router() // create a new Router
const todos = [] // and some fake todos
router
// middleware: withParams auto-parses route params into the request
.all('*', withParams)
// GET list of todos
.get('/todos', () => todos)
// GET single todo, by ID
.get('/todos/:id',
({ id }) => todos.find(todo => todo.id === id)
|| error(404, 'That todo was not found')
)
// 404 for everything else
.all('*', () => error(404))
// Example: Cloudflare Worker module syntax
export default {
fetch: (request, ...args) => router
.handle(request, ...args)
.then(json) // automatically send as JSON
.catch(error) // and send error Responses for thrown errors
}
Have a question? Suggestion? Complaint? Want to send me a gift basket?
Join us on Discord!
yarn
yarn dev
yarn verify
This repo goes out to my past and present colleagues at Arundo - who have brought me such inspiration, fun,
and drive over the last couple years. In particular, the absurd brevity of this code is thanks to a
clever [abuse] of Proxy
, courtesy of the brilliant @mvasigh.
This trick allows methods (e.g. "get", "post") to by defined dynamically by the router as they are requested,
drastically reducing boilerplate.
These folks are the real heroes, making open source the powerhouse that it is! Help out and get your name added to this list! <3
FAQs
A tiny, zero-dependency router, designed to make beautiful APIs in any environment.
The npm package itty-router receives a total of 0 weekly downloads. As such, itty-router popularity was classified as not popular.
We found that itty-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.