I’m designing a RESTful API and in an attempt to be descriptive and make documentation clearer I want to declare my content-type http header as follows:
Content-Type: application/vnd.mycorp.mydatatype+json
where mycorp is an identifier unique to my corporation and mydatatype is unique to each data type. An example would be:
Content-Type: application/vnd.ford.car+json
{
"manufactured_year": 2000
, "color": "blue"
, "hp": 160
, "model" "Focus"
, "type": "sedan"
}
This content-type would be required in order for a POST to be valid and would be sent as a part of a response. It seems to me like a nice way to define rules for what should be inside the payload.
I can’t seem to find a good resource on whether this is a good idea or if it is even allowed by IETF standards.
So, question is: Which is more feasible, application/vnd.mycorp.mydatatype+json or just application/json?
It’s allowed, definitely. Whether it’s a good idea is another story.
My rule of thumb is that it’s a primary data format that’s useful across a lot of things, needs to be identified on its own, and you need to interoperate across many applications, definitely give it a media type.
However, if it’s just a message in your API among many, and it’s only good for one resource (or one resource “type”), just use application/json.
YMMV, of course.