Skip to content

Feature request: ability to set settings per response #3536

Open
@bradvogel

Description

@bradvogel

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions