Skip to main content
Module

x/http_fns/media_type.ts>byMediaType

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

Create a Request handler that delegates based on the desired media-type of the Request.

The media-type is determined by extension on the URL path if it has one, otherwise it will examine the Accept header and choose the most appropriate type supplied.

Type Parameters

A extends unknown[]

Parameters

handlers: MediaTypeHandlers<A>

an object of handlers, where the key is the media-type

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

called when the URL has an extension but no handler matches, defaults to returning a Not Found response

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

called when the URL doesn't have an extension and a type handler can not be matched from the Accept header, defaults to a Not Acceptable response