Skip to main content
Module

x/reno/reno/formethod.ts>forMethod

A thin, testable routing library designed to sit on top of Deno's standard HTTP module
Latest
function forMethod
import { forMethod } from "https://deno.land/x/reno@v2.0.105/reno/formethod.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);