Question

I'm writing an app that looks at a Content-Type (e.g. application/json) to determine processing. Most of the time, the Content-Type is well known. However, sometimes it would be convenient to create a custom Content-Type (e.g. application/swagger' ortext/raml' or yaml/raml'). What are the ramifications of creating a custom Content-Type? How do browsers deal with them if I want to send them as an HTTP response? Does it matter whether I use text/swagger or application/swagger?

Était-ce utile?

La solution

For guidelines on creating custom or experimental Content-Type identifiers, see rfc6648.

Historically the recommendation was to prepend the identifier with "x-" but this has been deprecated. It sounds like the best practice is to try to ensure that you are registering your custom media type or using one that has already been registered (even if it's experimental)

As far as whether to use text/swagger or application/swagger I would suggest basing this off of the media type that Swagger uses which is JSON and since JSON is identified as application/json then Swagger would be something like application/swagger+json. Swagger can also include JSON Schema which is identified as application/schema+json

There's actually already a discussion on the Swagger mailing list that includes a proposal for application/swagger+json

Autres conseils

Browsers (don't know about chrome and chromera (opera next)) have configurations to define actions to mime types. If your content have to be parsed directly by browser (i.e. (x)(ht)ml, css, images..), it should contain correct mime type (i.e. "image/jpeg" if you want display jpeg image, if you send hello/omg, you can't expect that browser will show correct page, instead it will display some "Download" dialog window or something alike).

Content mime types should cover rfc2046: https://www.rfc-editor.org/rfc/rfc2046

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top