node-restify icon indicating copy to clipboard operation
node-restify copied to clipboard

`res.send` should be not auto-coerce to application/json

Open DonutEspresso opened this issue 7 years ago • 2 comments

  • [X] Used appropriate template for the issue type
  • [X] Searched both open and closed issues for duplicates of this issue
  • [X] Title adequately and concisely reflects the feature or the bug

Bug Report

When res.send is called, and a content-type is not explicitly set, application/json is chosen as the default content type if the first parameter received by send is a JS object. This behavior can be confusing (even more so when strictFormatters; false), and seems to be unnecessary given that res.json exists to do the same thing.

Something worth considering as we figure out how to decouple content negotiation from formatters moving forward.

cc @misterdjules

DonutEspresso avatar Dec 13 '18 23:12 DonutEspresso

/cc @cprussin @mridgway @jdarren

misterdjules avatar Dec 14 '18 01:12 misterdjules

I've just run into this and found it quite odd. I had thought that one of the benefits of Restify was that it will do content negotiation and yet most of the time it's application/json or nothing. (After all, most things in JavaScript are objects.)

In my case, I was considering returning HTML to browsers when a request results in an error. (Though I appreciate my use of Restify might be a little odd.)

It seems to me that for different things passed to res.send() it makes sense to prefer some content types over others but not to force them.

As things stand the first example on the getting started page appears to break as soon as one changes the value passed to res.send().

daniel-ac-martin avatar Apr 15 '20 16:04 daniel-ac-martin