🦕 VelociRouter

A minimal async RequestResponse router powered by URL Pattern API magic ✨

Documentation

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

Velocirouter Documentation

Notes

Only Deno and Chromium based browsers have URL Pattern API support right now. Other runtimes like Bun and Node require a polyfill.

Inspired by Polka and Hono.


MIT License | Copyright © 2024 David Bushell