Media type parameters: why are forbidden?


#1

Hi,
my question is: why media type parameters are forbidden? (http://jsonapi.org/format/#content-negotiation-servers).
Some media type parameters are very useful, for instance “charset”. Why I cant use it?
Thanks!


#2

Basically, a media type is meant to be a standardized, globally-known contract—it’s processing rules aren’t supposed to change from implementation to implementation. That’s why the IANA specification for how to register a media type says:

the names, values, and meanings of any parameters MUST be fully specified when a media type is registered in the standards tree, and SHOULD be specified as completely as possible when media types are registered in the vendor or personal trees.

So, if JSON API were to let users specify their own media type parameters, the same parameter would mean different things in different JSON API implementations, and that’s contrary to the spirit of a media type. (Implementation-specific information should be in the content of the response, not in the information about what type it is; that needs to be broadly understood.)

 

About the charset parameter in particular: the JSON media type, which JSON API extends, actually doesn’t define any parameters, including charset. Charset isn’t necessary because JSON is always unicode, and the type of Unicode in use can be figured out just by analyzing the content received. (Compliant JSON implementations will do this automatically.)

However, some web browsers and other clients used to mistakenly add a charset parameter on JSON requests, so a later revision of the JSON specification clarified that any charset provided can just be ignored (see the note at the bottom of this section). Luckily, all browsers have stopped doing this now, except for Firefox, which is working on a fix.

In order to support this Firefox bug, JSON API is going to add support for clients sending a charset parameter, which servers can just ignore. However, servers still won’t be allowed to use this parameter because, again, there’s no need for them to with JSON data (and no bugs to justify us making an exception).

If you feel there are features you need to support, and you were going to do so with a media type parameter, please open another thread on here and we can help you find alternate solutions.


#3

Thank you very much for the answer! :wink:

I have already observed that Firefox adds a charset parameter on JSON requests. I hope that a fix will come soon.

Bye.