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
Provenance
- Commit
5a48248- Tree
6e7fb4d- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
bedff32
3 files changed+56 added−0 removed
modified:docs/guide.1+21 added
209 unmodified lines210 .fi211 .212 .IP "" 0213 .214+.SS "ServerRequest#send(body|status[, headers|status[, status]])"215+The \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+.nf220+221+ 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+.P233+By 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])"236 Redirect to the given \fIurl\fR with a default response \fIstatus\fR of 302\.237 .238 .IP "" 465 unmodified linesmodified:docs/guide.html+18 added
312 unmodified lines313 connect.bodyDecoder()314 );315 </code></pre>316 317+<h3 id="ServerRequest-send-body-status-headers-status-status-">ServerRequest#send(body|status[, headers|status[, status]])</h3>318+319+<p>The <code>res.send()</code> method is a high level response utility allowing you to pass320+objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status321+code based responses. The following are all valid uses:</p>322+323+<pre><code> res.send(new Buffer('wahoo'));324+ res.send({ some: 'json' });325+ res.send('<p>some html</p>');326+ res.send('Sorry, cant find that', 404);327+ res.send('text', { 'Content-Type': 'text/plain' }, 201);328+ res.send(404);329+</code></pre>330+331+<p>By default the <em>Content-Type</em> response header is set, however if explicitly332+assigned through <code>res.send()</code> or previously with <code>res.header()</code> or <code>res.contentType()</code>333+it will not be set again.</p>334+335 <h3 id="ServerResponse-redirect-url-status-">ServerResponse#redirect(url[, status])</h3>336 337 <p>Redirect to the given <em>url</em> with a default response <em>status</em> of 302.</p>338 43 unmodified linesmodified:docs/guide.md+17 added
139 unmodified linesExpand all14014114214314414514614714814915015115215315415515615715815916016116216316433 unmodified lines139 unmodified linesExpand all connect.logger(), connect.bodyDecoder() );
### ServerRequest#send(body|status[, headers|status[, status]])
The `res.send()` method is a high level response utility allowing you to passobjects to respond with json, strings for html, arbitrary _Buffer_s or numbers for statuscode based responses. The following are all valid uses:
res.send(new Buffer('wahoo')); res.send({ some: 'json' }); res.send('<p>some html</p>'); res.send('Sorry, cant find that', 404); res.send('text', { 'Content-Type': 'text/plain' }, 201); res.send(404);
By default the _Content-Type_ response header is set, however if explicitlyassigned through `res.send()` or previously with `res.header()` or `res.contentType()`it will not be set again.
### ServerResponse#redirect(url[, status])
Redirect to the given _url_ with a default response _status_ of 302.
33 unmodified lines