Search code examples
servicestackcontent-negotiation

ServiceStack media type


I am reading the jsoiapi document

jsopi.org

Can some one help me understand this

Server Responsibilities

Servers MUST send all JSON API data in response documents with the header Content-Type: application/vnd.api+json without any media type parameters.

Servers MUST respond with a 415 Unsupported Media Type status code if a request specifies the header Content-Type: application/vnd.api+json with any media type parameters.

Servers MUST respond with a 406 Not Acceptable status code if a request's Accept header contains the JSON API media type and all instances of that media type are modified with media type parameters.

Note: The content negotiation requirements exist to allow future versions of this specification to use media type parameters for extension negotiation and versioning.

How do I achieve this in Servicestack and do I have to take the above with a grain of salt?

Servers MUST send all JSON API data in response documents with the header Content-Type: application/vnd.api+json without any media type parameters.

This can be done in AppHost by using DefaultContentType = MimeTypes.Json in the EndPointHostConfig

But what about the remaining two?


Solution

  • There's a number of ways you can return different ContentTypes including registering a new Custom Media Type Format whilst the Error Handling documentation lists a number of different ways to return custom HTTP Error responses.

    But the question would be why would go through the additional effort to change the universally accepted Mime Type for JSON with a vendor prefix? (causing issues for existing browsers and JSON clients). Is this just an academic exercise or is this meant to add real-world value?