Question

Is there any support for handling composed media types? Example:

Content-Type: application/contact+xml
Content-Type: application/document+json

I know there is the possibility of using a mediatypeformatter/mediatypemapping, but is there something else? Do I have to map the media types and classes by myself e.g. with custom attributes?

[MimeType("application/document+json")]
class Mydocument
{
}

The "MediaTypeHeaderValue" class seems not to support such composed media types. Is there a "best practice" for that?

Was it helpful?

Solution

HTTP spec allows for additional parameters to be defined for a media-type.

So this could be:

Content-Type: application/xml;.NET-Type=Customer

The convention of sub-subtype in the form of <type>/<sub-subtype>+<subtype> (+ separated) is not canonical AFAIK, and just a convention.

In any case, you need to a bit work on both ends to implement media type composition coherency. But having multiple content-type is just wrong according to the spec.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top