Tivie Tivie - 2 months ago 6x
HTTP Question

Can Media Type's suffix and subtype be used interchangeably?

Although it isn't stated directly in IETF RFC 6838, after reading the text (and consulting wikipedia) one can conclude that the general schema of a Media Type is as following:

type name / [ tree. ] subtype name [ +suffix ] [ ; parameters ]

Both Content Type and Accept HTTP Headers use Internet Media Types (as stated in RFC 2616).

RFC 6838 also states the following about "+suffixes":

"+suffix" constructs for as-yet unregistered structured syntaxes
SHOULD NOT be used, given the possibility of conflicts with future
suffix definitions.

RFC 6839 defines the following registered suffixes:

"+json", "+ber", "+der", "+fastinfoset", "+wbxml" and "+zip"

Now, take the following data:

"title": "<h1>Some formatted title</h1>",
"body": "here's a <b>long</b> formatted text with <i>stuff</i>"


  • Is
    a good media type for this?

  • What if, instead of JSON, I use YAML? (
    violates RFC 6839 since it's not registered)

  • And what if I want to build a parser that decodes data based on Content Type? Should I look for "subtype" or "suffix" for the appropriate "encoding"?

  1. RFC 2616 is obsolete. Please look at RFC 7231.

  2. I wouldn't use html+json for something that is a mix of HTML and JSON; you'd really need to translate all markup to JSON (at which point you'd realize that JSON doesn't work well for markup languages).

  3. But yes, you could use something+json, as long as you register.

  4. +yaml doesn't violate RFC 6839; but you would need to register it.

  5. Generic software can use the suffix to select a parser. XMLHTTPRequest's support for +xml is an example.