Skip to main content

🦕 VelociRouter

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

router.dinoear.com

const router = new Router();

router.use((request, response) => {
  console.log(`[${request.method}] ${request.url}`);
  return response;
});

Native JavaScript URL Pattern matching for routes.

router.get({pathname: '/api/hello/:name'}, (request, response, {match}) => {
  const {name} = match.pathname.groups;
  return new Response(`Hello ${name}!`);
});

Request & Response are forwarded through all matching routes in order.

router.all('/api/*', (request, response) => {
  if (response) {
    response.headers.set('x-api-version', '1');
  }
  return response;
});

Documentation

Find more documentation and usage at router.dinoear.com.

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 © 2023 David Bushell