🦕 VelociRouter

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

velocirouter.deno.dev

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 velocirouter.deno.dev.

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