Files
expressjs.com/en/api/req-accepts.jade
TJ Holowaychuk 9e957d4e2c Initial commit
2012-07-31 20:33:12 -07:00

39 lines
1.1 KiB
Plaintext

section
h3(id='req.accepts') req.accepts(types)
p.
Check if the given <code>types</code> are acceptable, returning
the best match when true, otherwise <code>undefined</code> - in which
case you should respond with 406 "Not Acceptable".
p.
The <code>type</code> value may be a single mime type string
such as "application/json", the extension name
such as "json", a comma-delimted list or an array. When a list
or array is given the <em>best</em> match, if any is returned.
+js.
// 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');
// => "json"