Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions _includes/api/en/5x/req-accepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,24 @@ req.accepts(['html', 'json'])
// => "json"
```

#### Example

```js
app.get('/resource', function (req, res) {
// Check which response type the client prefers
const type = req.accepts(['json', 'html'])

if (type === 'json') {
return res.json({ message: 'Hello world' })
}

if (type === 'html') {
return res.send('<p>Hello world</p>')
}

// If none of the supported types are acceptable
res.status(406).send('Not Acceptable')
})


For more information, or if you have issues or concerns, see [accepts](https://github.com/expressjs/accepts).
Loading