Skip to main content

An HTTP Request router built on top of the URLPattern API.

Works with
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
3 months ago (0.0.2)

URLPattern Router

An HTTP Request router built on top of the URLPattern API.

Demo

import { Router } from "./router.ts";

const router = new Router<Deno.ServeHandlerInfo>();

router.get("/", (_req, ctx) => {
  return new Response(`ip: ${ctx.remoteAddr.hostname}:${ctx.remoteAddr.port}`);
});

router.get("/contacts/:name", (_req, ctx) => {
  return new Response(`Contact: ${ctx.params.name}`);
});

Deno.serve(router.fetch);

Goals

Closely match the definition for a Request Handler set out by Steven Krouse.

a function that takes a Request as it’s first argument, can have arbitrary other arguments, and outputs a Response.

Add Package

deno add @simple/urlpattern-router

Import symbol

import * as mod from "@simple/urlpattern-router";

Add Package

npx jsr add @simple/urlpattern-router

Import symbol

import * as mod from "@simple/urlpattern-router";

Add Package

yarn dlx jsr add @simple/urlpattern-router

Import symbol

import * as mod from "@simple/urlpattern-router";

Add Package

pnpm dlx jsr add @simple/urlpattern-router

Import symbol

import * as mod from "@simple/urlpattern-router";