expressjs.com
expressjs.com copied to clipboard
Possible gap in documentation re res.json and res.jsonp
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.
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.
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!
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.