I came across a practice that I found quite common. I even found the web page that gave this name, but I forgot the name and can no longer find this page in google.
The practice is that every JSON response from a REST service should have the following structure:
{
"status": "ok",
"data": { ... }
}
or in case of an error:
{
"status": "error",
"message": "Something went wrong"
}
My question is: what is the meaning of this status property in JSON? In my opinion, this is what HTTP status codes were created for.
REST uses HTTP means of communication between the client and the server, for example, to delete, use the verb "DELETE". In the same way, 404 should be used if the resource is not found, etc. Therefore, in accordance with this thinking, any errors must be correctly encoded in HTTP status.
HTTP 200 JSON? , .
, "", URL. HTTP, "", .
:
- ( HTTP- HTTP- )
- , , , HTTP , , HTTP , JSON .