Skip to main content
Module

x/reno/reno/mod.ts>createRouteMap

A thin, testable routing library designed to sit on top of Deno's standard HTTP module
Latest
function createRouteMap
import { createRouteMap } from "https://deno.land/x/reno@v2.0.105/reno/mod.ts";

Creates a RouteMap, a Map that holds route handling functions and keys them by the path by which the router will make them accessible:

export const routes = createRouteMap([
  ["/home", () => new Response("Hello world!")],

  // Supports RegExp routes for further granularity
  [/^\/api\/swanson\/?([0-9]?)$/, async (req: AugmentedRequest) => {
    const [quotesCount = "1"] = req.routeParams;

    const res = await fetch(
      `https://ron-swanson-quotes.herokuapp.com/v2/quotes/${quotesCount}`,
    );

    return jsonResponse(await res.json());
  }],
]);

Parameters

routes: [RegExp | string, RouteHandler][]