Skip to content
Myr

request.md

This file

Path

docs/request.md

107 lines · 2.6 KiB · Markdown

Last changed by

update markdown docsTJ Holowaychukbefore adoption76aa718

History of this file

Take it

Added new dox API docsTJ Holowaychukbefore adoption7e81cad

lines 1–5why, one step back
1
2# req34 Request prototype.5

re-generate docsTJ Holowaychukbefore adoptionde6f300

line 6why, one step back
6# req.get

Added new dox API docsTJ Holowaychukbefore adoption7e81cad

lines 7–10why, one step back
7
8 Return request header.9 10 The `Referrer` header field is special-cased,

re-generate docsTJ Holowaychukbefore adoptionde6f300

line 11why, one step back
11 both `Referrer` and `Referer` are interchangeable.

Added new dox API docsTJ Holowaychukbefore adoption7e81cad

lines 12–19why, one step back
12
13 ## Examples14 15 req.get('Content-Type');16 // => "text/plain"17 18 req.get('content-type');19 // => "text/plain"

re-generate docsTJ Holowaychukbefore adoptionde6f300

line 20why, one step back
20

Added new dox API docsTJ Holowaychukbefore adoption7e81cad

lines 21–22why, one step back
21 req.get('Something');
22 // => undefined

re-generate docsTJ Holowaychukbefore adoptionde6f300

lines 23–24why, one step back
23
24 Aliased as `req.header()`.

Added new dox API docsTJ Holowaychukbefore adoption7e81cad

lines 25–41why, one step back
25
26# req.accepts()2728 Check if the given `type(s)` is acceptable, returning29 the best match when true, otherwise `undefined`, in which30 case you should respond with 406 "Not Acceptable".31 32 The `type` value may be a single mime type string33 such as "application/json", the extension name34 such as "json", a comma-delimted list such as "json, html, text/plain",35 or an array `["json", "html", "text/plain"]`. When a list36 or array is given the _best_ match, if any is returned.37 38 ## Examples39 40 // Accept: text/html41 req.accepts('html');

update markdown docsTJ Holowaychukbefore adoption76aa718

line 42why, one step back
42 // => "html"

Added new dox API docsTJ Holowaychukbefore adoption7e81cad

lines 43–78why, one step back
43
44 // Accept: text/*, application/json45 req.accepts('html');46 // => "html"47 req.accepts('text/html');48 // => "text/html"49 req.accepts('json, text');50 // => "json"51 req.accepts('application/json');52 // => "application/json"53 54 // Accept: text/*, application/json55 req.accepts('image/png');56 req.accepts('png');57 // => undefined58 59 // Accept: text/*;q=.5, application/json60 req.accepts(['html', 'json']);61 req.accepts('html, json');62 // => "json"6364# req.acceptsCharset()6566 Check if the given `charset` is acceptable,67 otherwise you should respond with 406 "Not Acceptable".6869# req.acceptsLanguage()7071 Check if the given `lang` is acceptable,72 otherwise you should respond with 406 "Not Acceptable".7374# req.param()7576 Return the value of param `name` when present or `defaultValue`.77 78 - Checks route placeholders, ex: _/user/:id_

update markdown docsTJ Holowaychukbefore adoption76aa718

line 79why, one step back
79 - Checks body params, ex: id=12, {"id":12}

Added new dox API docsTJ Holowaychukbefore adoption7e81cad

lines 80–107why, one step back
80 - Checks query string params, ex: ?id=12
81 82 To utilize request bodies, `req.body`83 should be an object. This can be done by using84 the `connect.bodyParser()` middleware.8586# req.is()8788 Check if the incoming request contains the "Content-Type" 89 header field, and it contains the give mime `type`.90 91 ## Examples92 93 // With Content-Type: text/html; charset=utf-894 req.is('html');95 req.is('text/html');96 req.is('text/*');97 // => true98 99 // When Content-Type is application/json100 req.is('json');101 req.is('application/json');102 req.is('application/*');103 // => true104 105 req.is('html');106 // => false107