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

x/reno/reno/mod.ts>forMethod

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

Takes mappings of HTTP methods and route handler functions, and returns a higher-order route handler that will forward requests to the correct handler by their method. Any requests whose method does not have an associated handler will result in a HTTP 405:

const get = () => new Response("You performed a HTTP GET!");
const post = () => new Response("You performed a HTTP POST!");

const routes = createRouteMap([
  ["/endpoint", forMethod([
    ["GET", get],
    ["POST", post],
  ])],
]);

export const methodsRouter = createRouter(routes);

Parameters

mappings: [HttpMethod, RouteHandler][]

Returns

RouteHandler