Skip to main content
Module

x/http_fns/method.ts>byMethod

A bunch of functions for building HTTP servers
Go to Latest
function byMethod
import { byMethod } from "https://deno.land/x/http_fns@v0.0.27/method.ts";

Create a Request handler that delegates based on the HTTP Method of the Request.

This will also provide default implementations of HEAD (if GET is declared) and OPTIONS methods.

Type Parameters

A extends unknown[]

Parameters

handlers: Partial<Record<HttpMethod, (request: Request, ...args: A) => Awaitable<Response | null>>>

an object of handlers, where the key is the HTTP method

optional
fallback: (request: Request, ...args: A) => Awaitable<Response | null> = [UNSUPPORTED]

a handler for any method not given, defaults to return a Method Not Allowed response, but may return null if you want the request to cascade to a later handler