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

Add JSONIFY_MIMETYPE configuration variable #1728

merged 1 commit into from
Apr 8, 2016


Copy link

@sloria sloria commented Feb 16, 2016

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.

@@ -1029,6 +1029,18 @@ def test_jsonify_prettyprint():
assert == 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.

Copy link


Copy link

LGTM, but the changelog entry is now for the wrong version.

Allow jsonify responses' mimetype to be configured
Copy link
Contributor Author

sloria commented Apr 8, 2016

OK, I've rebased with the latest master and put the changelog entry in the 1.0 section.

@davidism davidism merged commit 2bf477c into pallets:master Apr 8, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
@pallets pallets unlocked this conversation Jul 12, 2022
Copy link

I'm currently implementing a new "JSON provider" interface for customizing how an app handles JSON. As part of that, I'm deprecating the app.config["JSONIFY_MIMETYPE"] parameter in favor of setting app.json.mimetype (along with some other config that makes more sense as provider setup).

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/"
        return response

app.json = VndProvider(app)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

5 participants