Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is empty body correct if Content-Type is application/json?

I return Status code 401 if token is wrong for the endpoint '/tokens/verify' and don't need to send any body content to user.

Is it correct to send an empty body for application/json content type?

like image 379
Sergei Basharov Avatar asked Nov 15 '16 16:11

Sergei Basharov


People also ask

What is the correct content type for JSON?

JSON has to be correctly interpreted by the browser to be used appropriately. text/plain was typically used for JSON, but according to IANA, the official MIME type for JSON is application/json .

Can content type empty?

Instead, browsers can just reuse the cache stored in the browser to display the content to the user. In this case, since the HTTP 304 response doesn't transmit any content back to the browser, this also means that there will be no response body and leading to “Empty” content type.


1 Answers

No, it's not. If you declare the payload to be JSON, you need to send JSON. The status code is irrelevant with respect to this.

Empty body is not valid JSON. Minimum valid JSON would be {}, [], "" (empty string enclosed in quotes), null, etc., but empty body is not valid JSON.

like image 99
Julian Reschke Avatar answered Sep 23 '22 07:09

Julian Reschke