🦕 VelociRouter
A minimal async Request
→ Response
router powered by URL Pattern API magic ✨
Usage
Add dependency from JSR: @ssr/velocirouter
const router = new Router();
router.use(({request}) => {
console.log(`[${request.method}] ${request.url}`);
});
Native JavaScript URL Pattern matching for routes.
router.get({pathname: '/api/hello/:name'}, ({match}) => {
const {name} = match.pathname.groups;
return new Response(`Hello ${name}!`);
});
Request
& Response
are forwarded through all matching routes in order.
router.all('/api/*', ({response}) => {
if (response) {
response.headers.set('x-api-version', '1');
}
return response;
});
Documentation
Notes
Only Deno and Chromium based browsers have URL Pattern API support right now. Other runtimes like Bun and Node require a polyfill.
MIT License | Copyright © 2024 David Bushell