Skip to main content
Deno 2 is finally here 🎉️
Learn more

http-router

deno land deno doc npm GitHub

HTTP request router for standard Request and Response.

  • URL pattern matching
  • Tiny, lean

Usage

core:

  • createRouter - Create HTTP request router.

types:

  • Method - HTTP request method.
  • RouteHandler - A handler for HTTP route requests.
  • Routes - HTTP request routes.
  • Router - HTTP request router API.
import { createRouter } from "https://deno.land/x/http_router@$VERSION/mod.ts";
import { serve } from "https://deno.land/std@$VERSION/http/mod.ts";
const router = createRouter({
  "/api/students/:name": {
    GET: (req, params) => {
      const greeting = `Hello! ${params.name!}`;
      return new Response(greeting);
    },
  },
  "/api/status": () => new Response("OK"), // Any HTTP request method
});
await serve(router);

Performance

Benchmark script with comparison to several popular routers is available. Run it with deno bench --unstable.

License

Copyright © 2022-present httpland.

Released under the MIT license