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

Possible gap in documentation re res.json and res.jsonp #1330

Open
jafrank88 opened this issue Mar 17, 2022 · 3 comments
Open

Possible gap in documentation re res.json and res.jsonp #1330

jafrank88 opened this issue Mar 17, 2022 · 3 comments

Comments

@jafrank88
Copy link

The documentation for 4.x, under res.jsonp() says, "res.jsonp([body])
Sends a JSON response with JSONP support. This method is identical to res.json(), except that it opts-in to JSONP callback support."

It appears that part of res.jsonp involves changing the content-type from 'application/json' to 'text/javascript'. I understand why this happens (RFC JSON Schema), but is there a setting or other way to keep the 'incorrect' content-type? Otherwise, maybe amend the documentation to note all the ways in which res.jsonp differs from res.json.
Thanks for considering it.

@dougwilson dougwilson transferred this issue from expressjs/express Mar 17, 2022
@dougwilson
Copy link
Contributor

Hi, thanks for opening this issue. I have moved it to the website repo, since your issue it about documentation. Please feel free to open a pull request with a fix you feel is appropriate if you are so inclined, otherwise we'll get the docs updated.

@jafrank88
Copy link
Author

Thank you so much! Sorry to have put it in the wrong place. The client is trying to get JSON, but wants it sent back via JSONP but with content-type 'application/json' and I am just trying to figure out if it is possible in Express, or whether I should be jumping out to Node. I don't have a suggestion for how to improve the documentation because I am not sure what other differences there are between res.json and res.jsonp other than the addition of the callback and the change in content-type. Thanks again!

@dougwilson
Copy link
Contributor

Hi, not it is not possible to change the content type, as there is no other acceptable type a web browser will accept for jsonp. You can customize the type for pure json responses, though.

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

No branches or pull requests

3 participants