Module

x/opine/deps.ts>typeofrequest

Fast, minimalist web framework for Deno ported from ExpressJS.
Go to Latest
function typeofrequest
import { typeofrequest } from "https://dotland.deno.dev/x/opine@2.2.0/deps.ts";

Check if the incoming request's header contains the "Content-Type" header field, and it contains any of the give mime types. If there is no request body, null is returned. If there is no content type, false is returned. Otherwise, it returns the first type that matches.

Examples:

// With Content-Type: text/html; charset=utf-8
typeofrequest(header, [ 'html' ]); // => 'html'
typeofrequest(header, ['text/html' ]); // => 'text/html'
typeofrequest(header, ['text/*', 'application/json' ]); // => 'text/html'

// When Content-Type is application/json
typeofrequest(header, [ 'json', 'urlencoded' ]); // => 'json'
typeofrequest(header, [ 'application/json' ]); // => 'application/json'
typeofrequest(header, [ 'html', 'application/*' ]); // => 'application/json'

typeofrequest(header, [ 'html' ]); // => false

Parameters

header: Headers
optional
types_: string[]

Returns

null | boolean | string