Feature request: ability to set settings per response
- Dominant language
- JavaScript
- Stars
- 69.5k
- Forks
- 25k
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 9
Description
I'd like to implement middleware that returns formatted json in the response when `pretty_ouput` is present on the query. I attempted this with the following code:
```js
// This code does not work as expected.
app.use(function(req, res, next) {
// Querystring `pretty_output` should prettify json output.
if (req.query['pretty_ouput']) {
app.set('json spaces', 2); // I'd like to set this only for this one request.
}
next();
});
```
However, subsequent requests without the `pretty_ouput` querystring are also formatted.
Is there a way to set the setting `json spaces` for only one request? Ideally I could call `res.set('json spaces', 2)` that would set this option for only this one response. I'd think this would be generically useful for any Express option.
Contributor guide
Assessment
This issue has not been assessed yet.