Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Add JSONIFY_MIMETYPE configuration variable#1728

Merged
davidism merged 1 commit intopallets:masterfrom
sloria:jsonify-mimetype
Apr 8, 2016
Merged

Add JSONIFY_MIMETYPE configuration variable#1728
davidism merged 1 commit intopallets:masterfrom
sloria:jsonify-mimetype

Conversation

@sloria
Copy link
Contributor

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 theContent-Type: applications/vnd.api+json header.


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.

@jeffwidman
Copy link
Contributor

LGTM

@untitaker
Copy link
Contributor

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

Allow jsonify responses' mimetype to be configured
@sloria
Copy link
ContributorAuthor

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

@davidismdavidism merged commit2bf477c intopallets:masterApr 8, 2016
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsNov 14, 2020
@palletspallets unlocked this conversationJul 12, 2022
@davidism
Copy link
Member

I'm currently implementing a new "JSON provider" interface for customizing how an app handles JSON. As part of that, I'm deprecating theapp.config["JSONIFY_MIMETYPE"] parameter in favor of settingapp.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"returnresponse

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:

classVndProvider(DefaultJSONProvider):defresponse(self,*args,**kwargs):response=super().response(*args,**kwargs)response.mimetype="application/vnd.cool-api.v1+json"returnresponseapp.json=VndProvider(app)

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJul 27, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@sloria@jeffwidman@untitaker@davidism@ThiefMaster

[8]ページ先頭

©2009-2026 Movatter.jp