What should be the content of "No Content" and "Accepted" responses?


#1

I am wondering what to send in the body when you return a “No Content” or “Accepted” response?

As I know, body of “No Content” responses are usually removed by web servers, but the spec requires successful responses to contain either “data”, “links” or “meta” top-level members in the body. What do you think whether it is an ambiguity or not? Should the specification be updated to clarify that successful JSON API responses can also be empty if sent as “204 No Content”?

Regarding the “Accepted” status code: what is usually sent in the body? Maybe only the meta top-level member? Or could I just send an empty body too?


#2

JSON-API does not require responses to contain a body.

This normative sentence from the specification is specifically worded to support things like 204 responses:

A JSON object MUST be at the root of every JSON API request and response containing data.


#3

Ahh, thanks for the reply! I have read the spec for hundreds of times but I couldn’t spot it unfortunately :S


#4

I’d add: while 204 responses shouldn’t contain a body (and, as @tkellen pointed out, aren’t required to), we do have some recommendations for the contents of “202 Accepted” responses. See http://jsonapi.org/recommendations/#asynchronous-processing


#5

I’m unsure about the content headers. Should the response contain a Content-Type header or not?

The Spec states

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

But as it’s not a response document it would make sense to not include the Header, also this means a little inconsistency to taken care of in client libraries.