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

x/opine/src/request.ts>WrappedRequest#accepts

Minimalist web framework for Deno ported from ExpressJS.
Latest
method WrappedRequest.prototype.accepts
import { WrappedRequest } from "https://deno.land/x/opine@2.3.4/src/request.ts";

Check if the given type(s) is acceptable, returning the best match when true, otherwise undefined, in which case you should respond with 406 "Not Acceptable".

The type value may be a single MIME type string such as "application/json", an extension name such as "json", a comma-delimited list such as "json, html, text/plain", an argument list such as "json", "html", "text/plain", or an array ["json", "html", "text/plain"]. When a list or array is given, the best match, if any is returned.

Examples:

// Accept: text/html
req.accepts('html');
// => "html"

// Accept: text/*, application/json
req.accepts('html');
// => "html"
req.accepts('text/html');
// => "text/html"
req.accepts('json, text');
// => "json"
req.accepts('application/json');
// => "application/json"

// Accept: text/*, application/json
req.accepts('image/png');
req.accepts('png');
// => undefined

// Accept: text/*;q=.5, application/json
req.accepts(['html', 'json']);
req.accepts('html', 'json');
req.accepts('html, json');
// => "json"

Parameters

...args: [string[]] | string[]