Content-Type for JSON:API Specification
Set the Content-Type header for JSON:API (jsonapi.org) compliant requests. Covers the application/vnd.api+json media type and its requirements.
Detailed Explanation
JSON:API Media Type
The JSON:API specification (jsonapi.org) defines its own media type to distinguish JSON:API payloads from generic JSON.
The Header Value
Content-Type: application/vnd.api+json
Important Rules
The JSON:API specification has strict requirements around the Content-Type header:
No charset parameter: Clients and servers must not include any media type parameters (like charset) in the Content-Type header when using
application/vnd.api+json. Any request with parameters must be rejected with a415 Unsupported Media Typeresponse.Accept header: Clients should also set
Accept: application/vnd.api+jsonto indicate they expect a JSON:API response.Extension negotiation: JSON:API 1.1 introduced extension negotiation via the
extandprofileparameters, but these are the only allowed parameters.
Request Example
{
"data": {
"type": "articles",
"attributes": {
"title": "New Article",
"body": "Article content..."
},
"relationships": {
"author": {
"data": { "type": "people", "id": "9" }
}
}
}
}
curl Example
curl -X POST \
-H "Content-Type: application/vnd.api+json" \
-H "Accept: application/vnd.api+json" \
-d '{"data":{"type":"articles","attributes":{"title":"Hello"}}}' \
https://api.example.com/articles
Use Case
Use this when building or consuming APIs that follow the JSON:API specification, such as those built with Ember Data, JSONAPI::Resources (Ruby), or Laravel JSON:API.