Skip to content

Commit

Permalink
update express.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 8, 2012
1 parent f3981b3 commit 79d9bff
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions express.md
Expand Up @@ -220,7 +220,7 @@

// Accept: text/html
req.accepts('html');
// => "html"
// => "html"

// Accept: text/*, application/json
req.accepts('html');
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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(){
Expand All @@ -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()

Expand All @@ -442,18 +441,14 @@

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`.

## Options

- `maxAge` max-age in milliseconds, converted to `expires`
- `signed` sign the cookie
- `path` defaults to "/"

## Examples
Expand Down

0 comments on commit 79d9bff

Please sign in to comment.