update markdown 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 0acee67 · Browse files · 3 files·+34 added−44 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+34 added−44 removed
- other:+34 added−44 removed
Provenance
- Commit
76aa718- Tree
180e47b- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
0acee67
3 files changed+34 added−44 removed
modified:docs/express.md+17 added-22 removed
218 unmodified lines219 ## Examples220 221 // Accept: text/html222 req.accepts('html');223- // => "html"223+ // => "html"224 225 // Accept: text/*, application/json226 req.accepts('html');227 // => "html"27 unmodified lines255 # req.param()256 257 Return the value of param `name` when present or `defaultValue`.258 259- - Checks body params, ex: id=12, {"id":12}259 - Checks route placeholders, ex: _/user/:id_260+ - Checks body params, ex: id=12, {"id":12}261 - Checks query string params, ex: ?id=12262 263 To utilize request bodies, `req.body`264 should be an object. This can be done by using19 unmodified lines284 // => true285 286 req.is('html');287 // => false288- 289- Now within our route callbacks, we can use to to assert content types290- such as "image/jpeg", "image/png", etc.291- 292- app.post('/image/upload', function(req, res, next){293- if (req.is('image/*')) {294- // do something295- } else {296- next();297- }298- });288 289 290 # res291 68 unmodified lines360 Optionally providing an alternate attachment `filename`,361 and optional callback `fn(err)`. The callback is invoked362 when the data transfer is complete, or when an error has363 ocurred. Be sure to check `res.headerSent` if you plan to respond.364+ 365+ This method uses `res.sendfile()`.366 367 # res.format()368 369 Respond to the Acceptable formats using an `obj`24 unmodified lines394 }395 });396 397 In addition to canonicalized MIME types you may407- ## also use extnames mapped to these types398+ also use extnames mapped to these types:399 400 res.format({401 text: function(){402 res.send('hey');4 unmodified lines407 },408 409 json: function(){410 res.send({ message: 'hey' });420- }411+ }412 });413+ 414+ By default Express passes an `Error`415+ with a `.status` of 406 to `next(err)`416+ if a match is not made, however you may417+ provide an optional callback `fn` to418+ be invoked instead.419 420 # res.attachment()421 422 Set _Content-Disposition_ header to _attachment_ with optional `filename`.423 427-# res.set()424+# res.set425 426 Set header `field` to `val`, or pass430- an object of of header fields.427+ an object of header fields.428 429 ## Examples430 431 res.set('Accept', 'application/json');432 res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });433+ 434+ Aliased as `res.header()`.435 436 # res.get()437 438 Get value for header `field`.1 unmodified line440 # res.clearCookie()441 442 Clear cookie `name`.443 445-# res.signedCookie()446-447- Set a signed cookie with the given `name` and `val`.448- See `res.cookie()` for details.449-444 # res.cookie()445 446 Set cookie `name` to `val`, with the given `options`.447 448 ## Options449 450 - `maxAge` max-age in milliseconds, converted to `expires`451+ - `signed` sign the cookie452 - `path` defaults to "/"453 454 ## Examples455 51 unmodified linesmodified:docs/request.md+2 added-13 removed
37 unmodified lines3839404142424344454627 unmodified lines747576777878798081828319 unmodified lines10310410510610710810911011111211311411511611710737 unmodified lines ## Examples // Accept: text/html req.accepts('html'); // => "html" // => "html" // Accept: text/*, application/json req.accepts('html'); // => "html"27 unmodified lines# req.param()
Return the value of param `name` when present or `defaultValue`. - Checks body params, ex: id=12, {"id":12} - Checks route placeholders, ex: _/user/:id_ - Checks body params, ex: id=12, {"id":12} - Checks query string params, ex: ?id=12 To utilize request bodies, `req.body` should be an object. This can be done by using19 unmodified lines // => true req.is('html'); // => false Now within our route callbacks, we can use to to assert content types such as "image/jpeg", "image/png", etc. app.post('/image/upload', function(req, res, next){ if (req.is('image/*')) { // do something } else { next(); } });
modified:docs/response.md+15 added-9 removed
71 unmodified lines72 Optionally providing an alternate attachment `filename`,73 and optional callback `fn(err)`. The callback is invoked74 when the data transfer is complete, or when an error has75 ocurred. Be sure to check `res.headerSent` if you plan to respond.76+ 77+ This method uses `res.sendfile()`.78 79 # res.format()80 81 Respond to the Acceptable formats using an `obj`24 unmodified lines106 }107 });108 109 In addition to canonicalized MIME types you may108- ## also use extnames mapped to these types110+ also use extnames mapped to these types:111 112 res.format({113 text: function(){114 res.send('hey');4 unmodified lines119 },120 121 json: function(){122 res.send({ message: 'hey' });121- }123+ }124 });125+ 126+ By default Express passes an `Error`127+ with a `.status` of 406 to `next(err)`128+ if a match is not made, however you may129+ provide an optional callback `fn` to130+ be invoked instead.131 132 # res.attachment()133 134 Set _Content-Disposition_ header to _attachment_ with optional `filename`.135 128-# res.set()136+# res.set137 138 Set header `field` to `val`, or pass131- an object of of header fields.139+ an object of header fields.140 141 ## Examples142 143 res.set('Accept', 'application/json');144 res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });145+ 146+ Aliased as `res.header()`.147 148 # res.get()149 150 Get value for header `field`.1 unmodified line152 # res.clearCookie()153 154 Clear cookie `name`.155 146-# res.signedCookie()147-148- Set a signed cookie with the given `name` and `val`.149- See `res.cookie()` for details.150-156 # res.cookie()157 158 Set cookie `name` to `val`, with the given `options`.159 160 ## Options161 162 - `maxAge` max-age in milliseconds, converted to `expires`163+ - `signed` sign the cookie164 - `path` defaults to "/"165 166 ## Examples167 51 unmodified lines