Skip to content
Myr

More docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent bcf9f00 · Browse files · 3 files+247 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+247 added−0 removed

  • other:+247 added−0 removed

3 files+247 added−0 removed

modified:docs/guide.1+100 added
209 unmodified lines
210.fi211.212.IP "" 0213.214.SS "ServerRequest#header(key[, defaultValue])"215Get the case\-insensitive request header \fIkey\fR, with optional \fIdefaultValue\fR:216.217.IP "" 4218.219.nf220221req\.header(\'Host\');222req\.header(\'host\');223req\.header(\'Accept\', \'*/*\');224.225.fi226.227.IP "" 0228.229.SS "ServerRequest#accepts(type)"230Check if the \fIAccept\fR header is present, and includes the given \fItype\fR\.231.232.P233When the \fIAccept\fR header is not present \fItrue\fR is returned\. Otherwise the given \fItype\fR is matched by an exact match, and then subtypes\. You may pass the subtype such as \"html\" which is then converted internally to \"text/html\" using the mime lookup table\.234.235.IP "" 4236.237.nf238239// Accept: text/html240req\.accepts(\'html\');241// => true242243// Accept: text/*; application/json244req\.accepts(\'html\');245req\.accepts(\'text/html\');246req\.accepts(\'text/plain\');247req\.accepts(\'application/json\');248// => true249250req\.accepts(\'image/png\');251req\.accepts(\'png\');252// => false253.254.fi255.256.IP "" 0257.258.SS "ServerRequest#param(name)"259Return the value of param \fIname\fR when present\.260.261.IP "\(bu" 4262Checks route placeholders, ex: /user/:id263.264.IP "\(bu" 4265Checks query string params, ex: ?id=12266.267.IP "\(bu" 4268Checks urlencoded body params, ex: id=12269.270.IP "" 0271.272.P273To utilize urlencoded request bodies, \fIreq\.body\fR should be an object\. This can be done by using the \fIconnect\.bodyDecoder\fR middleware\.274.275.SS "ServerRequest#flash(type[, msg])"276Queue flash \fImsg\fR of the given \fItype\fR\.277.278.IP "" 4279.280.nf281282req\.flash(\'info\', \'email sent\');283req\.flash(\'error\', \'email delivery failed\');284req\.flash(\'info\', \'email re\-sent\');285// => 2286287req\.flash(\'info\');288// => [\'email sent\', \'email re\-sent\']289290req\.flash(\'info\');291// => []292293req\.flash();294// => { error: [\'email delivery failed\'], info: [] }295.296.fi297.298.IP "" 0299.300.SS "ServerRequest#isXMLHttpRequest"301Also aliased as \fIreq\.xhr\fR, this getter checks the \fIX\-Requested\-With\fR header to see if it was issued by an \fIXMLHttpRequest\fR:302.303.IP "" 4304.305.nf306307req\.xhr308req\.isXMLHttpRequest309.310.fi311.312.IP "" 0313.314.SS "ServerResponse#header(key[, val])"315Get or set the response header \fIkey\fR\.316.317.IP "" 4
178 unmodified lines
modified:docs/guide.html+77 added
312 unmodified lines
313 connect.bodyDecoder()314);315</code></pre>316317<h3 id="ServerRequest-header-key-defaultValue-">ServerRequest#header(key[, defaultValue])</h3>318319<p>Get the case-insensitive request header <em>key</em>, with optional <em>defaultValue</em>:</p>320321<pre><code>req.header('Host');322req.header('host');323req.header('Accept', '*/*');324</code></pre>325326<h3 id="ServerRequest-accepts-type-">ServerRequest#accepts(type)</h3>327328<p>Check if the <em>Accept</em> header is present, and includes the given <em>type</em>.</p>329330<p>When the <em>Accept</em> header is not present <em>true</em> is returned. Otherwise331the given <em>type</em> is matched by an exact match, and then subtypes. You332may pass the subtype such as "html" which is then converted internally333to "text/html" using the mime lookup table.</p>334335<pre><code>// Accept: text/html336req.accepts('html');337// =&gt; true338339// Accept: text/*; application/json340req.accepts('html');341req.accepts('text/html');342req.accepts('text/plain');343req.accepts('application/json');344// =&gt; true345346req.accepts('image/png');347req.accepts('png');348// =&gt; false349</code></pre>350351<h3 id="ServerRequest-param-name-">ServerRequest#param(name)</h3>352353<p>Return the value of param <em>name</em> when present.</p>354355<ul>356<li>Checks route placeholders, ex: /user/:id</li>357<li>Checks query string params, ex: ?id=12</li>358<li>Checks urlencoded body params, ex: id=12</li>359</ul>360361362<p>To utilize urlencoded request bodies, <em>req.body</em>363should be an object. This can be done by using364the <em>connect.bodyDecoder</em> middleware.</p>365366<h3 id="ServerRequest-flash-type-msg-">ServerRequest#flash(type[, msg])</h3>367368<p>Queue flash <em>msg</em> of the given <em>type</em>.</p>369370<pre><code>req.flash('info', 'email sent');371req.flash('error', 'email delivery failed');372req.flash('info', 'email re-sent');373// =&gt; 2374375req.flash('info');376// =&gt; ['email sent', 'email re-sent']377378req.flash('info');379// =&gt; []380381req.flash();382// =&gt; { error: ['email delivery failed'], info: [] }383</code></pre>384385<h3 id="ServerRequest-isXMLHttpRequest">ServerRequest#isXMLHttpRequest</h3>386387<p>Also aliased as <em>req.xhr</em>, this getter checks the <em>X-Requested-With</em> header388to see if it was issued by an <em>XMLHttpRequest</em>:</p>389390<pre><code>req.xhr391req.isXMLHttpRequest392</code></pre>393394<h3 id="ServerResponse-header-key-val-">ServerResponse#header(key[, val])</h3>395396<p>Get or set the response header <em>key</em>.</p>397
115 unmodified lines
modified:docs/guide.md+70 added
139 unmodified lines
140 connect.logger(),141 connect.bodyDecoder()142 );143144### ServerRequest#header(key[, defaultValue])145146Get the case-insensitive request header _key_, with optional _defaultValue_:147148 req.header('Host');149 req.header('host');150 req.header('Accept', '*/*');151152### ServerRequest#accepts(type)153154Check if the _Accept_ header is present, and includes the given _type_.155156When the _Accept_ header is not present _true_ is returned. Otherwise157the given _type_ is matched by an exact match, and then subtypes. You158may pass the subtype such as "html" which is then converted internally159to "text/html" using the mime lookup table.160161 // Accept: text/html162 req.accepts('html');163 // => true164165 // Accept: text/*; application/json166 req.accepts('html');167 req.accepts('text/html');168 req.accepts('text/plain');169 req.accepts('application/json');170 // => true171172 req.accepts('image/png');173 req.accepts('png');174 // => false175176### ServerRequest#param(name)177178Return the value of param _name_ when present.179180 - Checks route placeholders, ex: /user/:id181 - Checks query string params, ex: ?id=12182 - Checks urlencoded body params, ex: id=12183184To utilize urlencoded request bodies, _req.body_185should be an object. This can be done by using186the _connect.bodyDecoder_ middleware.187188### ServerRequest#flash(type[, msg])189190Queue flash _msg_ of the given _type_.191192 req.flash('info', 'email sent');193 req.flash('error', 'email delivery failed');194 req.flash('info', 'email re-sent');195 // => 2196197 req.flash('info');198 // => ['email sent', 'email re-sent']199200 req.flash('info');201 // => []202203 req.flash();204 // => { error: ['email delivery failed'], info: [] }205206### ServerRequest#isXMLHttpRequest207208Also aliased as _req.xhr_, this getter checks the _X-Requested-With_ header209to see if it was issued by an _XMLHttpRequest_:210211 req.xhr212 req.isXMLHttpRequest213214### ServerResponse#header(key[, val])215216Get or set the response header _key_.217
98 unmodified lines