Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update express.md

  • Loading branch information...
commit 79d9bff4f4a223c92be8820dbdb164ab22785ab9 1 parent f3981b3
@tj authored
Showing with 17 additions and 22 deletions.
  1. +17 −22 express.md
View
39 express.md
@@ -220,7 +220,7 @@
// Accept: text/html
req.accepts('html');
- // => "html"
+ // => "html"
// Accept: text/*, application/json
req.accepts('html');
@@ -256,8 +256,8 @@
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`
@@ -285,17 +285,6 @@
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();
- }
- });
# res
@@ -372,6 +361,8 @@
and optional callback `fn(err)`. The callback is invoked
when the data transfer is complete, or when an error has
ocurred. Be sure to check `res.headerSent` if you plan to respond.
+
+ This method uses `res.sendfile()`.
# res.format()
@@ -404,7 +395,7 @@
});
In addition to canonicalized MIME types you may
- ## also use extnames mapped to these types
+ also use extnames mapped to these types:
res.format({
text: function(){
@@ -417,22 +408,30 @@
json: function(){
res.send({ message: 'hey' });
- }
+ }
});
+
+ By default Express passes an `Error`
+ with a `.status` of 406 to `next(err)`
+ if a match is not made, however you may
+ provide an optional callback `fn` to
+ be invoked instead.
# res.attachment()
Set _Content-Disposition_ header to _attachment_ with optional `filename`.
-# res.set()
+# res.set
Set header `field` to `val`, or pass
- an object of of header fields.
+ an object of header fields.
## Examples
res.set('Accept', 'application/json');
res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
+
+ Aliased as `res.header()`.
# res.get()
@@ -442,11 +441,6 @@
Clear cookie `name`.
-# res.signedCookie()
-
- Set a signed cookie with the given `name` and `val`.
- See `res.cookie()` for details.
-
# res.cookie()
Set cookie `name` to `val`, with the given `options`.
@@ -454,6 +448,7 @@
## Options
- `maxAge` max-age in milliseconds, converted to `expires`
+ - `signed` sign the cookie
- `path` defaults to "/"
## Examples
Please sign in to comment.
Something went wrong with that request. Please try again.