Add JSONIFY_MIMETYPE configuration variable#1728
Conversation
|
|
||
| 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 responseAm 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+jsonheader.