-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
Add JSONIFY_MIMETYPE configuration variable #1728
Conversation
@@ -1029,6 +1029,18 @@ def test_jsonify_prettyprint(): | |||
assert rv.data == pretty_response | |||
|
|||
|
|||
def test_jsonify_mimetype(): | |||
app = flask.Flask(__name__) | |||
app.config.update({"JSONIFY_MIMETYPE": 'application/vnd.api+json'}) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
6afffdb
to
a3c574f
Compare
LGTM |
LGTM, but the changelog entry is now for the wrong version. |
Allow jsonify responses' mimetype to be configured
OK, I've rebased with the latest |
I'm currently implementing a new "JSON provider" interface for customizing how an app handles JSON. As part of that, I'm deprecating the However, reviewing this I'm not clear that setting the mimetype unconditionally is correct. The JSON API mimetype seems to be specifically for responses related to its own metadata and introspection, not to the actual API responses. It makes much more sense to me to set the content type for the specific responses that need it: response = jsonify(data)
response.mimetype = "application/vnd.api+json"
return response Am I missing something here or can I remove the configuration entirely? Note that it would still be possible to change the default using a custom provider: class VndProvider(DefaultJSONProvider):
def response(self, *args, **kwargs):
response = super().response(*args, **kwargs)
response.mimetype = "application/vnd.cool-api.v1+json"
return response
app.json = VndProvider(app) |
It is often useful to be able to return a vendor media type for JSON responses. For example, JSON API requires that all responses have the
Content-Type: applications/vnd.api+json
header.