Skip to content
Myr

Docs for res.send()

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 bedff32 · Browse files · 3 files+56 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+56 added−0 removed

  • other:+56 added−0 removed

3 files+56 added−0 removed

modified:docs/guide.1+21 added
209 unmodified lines
210.fi211.212.IP "" 0213.214.SS "ServerRequest#send(body|status[, headers|status[, status]])"215The \fBres\.send()\fR method is a high level response utility allowing you to pass objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status code based responses\. The following are all valid uses:216.217.IP "" 4218.219.nf220221 res\.send(new Buffer(\'wahoo\'));222 res\.send({ some: \'json\' });223 res\.send(\'<p>some html</p>\');224 res\.send(\'Sorry, cant find that\', 404);225 res\.send(\'text\', { \'Content\-Type\': \'text/plain\' }, 201);226 res\.send(404);227.228.fi229.230.IP "" 0231.232.P233By default the \fIContent\-Type\fR response header is set, however if explicitly assigned through \fBres\.send()\fR or previously with \fBres\.header()\fR or \fBres\.contentType()\fR it will not be set again\.234.235.SS "ServerResponse#redirect(url[, status])"236Redirect to the given \fIurl\fR with a default response \fIstatus\fR of 302\.237.238.IP "" 4
65 unmodified lines
modified:docs/guide.html+18 added
312 unmodified lines
313 connect.bodyDecoder()314);315</code></pre>316317<h3 id="ServerRequest-send-body-status-headers-status-status-">ServerRequest#send(body|status[, headers|status[, status]])</h3>318319<p>The <code>res.send()</code> method is a high level response utility allowing you to pass320objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status321code based responses. The following are all valid uses:</p>322323<pre><code> res.send(new Buffer('wahoo'));324 res.send({ some: 'json' });325 res.send('&lt;p&gt;some html&lt;/p&gt;');326 res.send('Sorry, cant find that', 404);327 res.send('text', { 'Content-Type': 'text/plain' }, 201);328 res.send(404);329</code></pre>330331<p>By default the <em>Content-Type</em> response header is set, however if explicitly332assigned through <code>res.send()</code> or previously with <code>res.header()</code> or <code>res.contentType()</code>333it will not be set again.</p>334335<h3 id="ServerResponse-redirect-url-status-">ServerResponse#redirect(url[, status])</h3>336337<p>Redirect to the given <em>url</em> with a default response <em>status</em> of 302.</p>338
43 unmodified lines
modified:docs/guide.md+17 added