Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
DonutEspresso opened this issue Dec 13, 2018 · 2 comments
Open
3 tasks done

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

DonutEspresso opened this issue Dec 13, 2018 · 2 comments

Comments

@DonutEspresso
Copy link
Member

  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • 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

@misterdjules
Copy link
Contributor

/cc @cprussin @mridgway @jdarren

@daniel-ac-martin
Copy link

daniel-ac-martin commented Apr 15, 2020

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants