Reputation: 169
We are implementing a REST based web service and we have some queries on some of the use cases.
Consider there is a unique account which contains some information (Ex. added to cart information)
What HTTP statuscode shall be used?
Upvotes: 11
Views: 21105
Reputation: 3317
See This Blog. It explains it very well.
Summary of the blog's comments on 204:
The answer, therefore, to your question is use 404 in your case. 204 is a specialized reponse code that you shouldn't often return to a browser in response to a GET.
The other response codes are even less appropriate than 204 and 404.
Wikipedia's description of the HTTP status codes are particularly helpful. You can also see the definitions in the HTTP/1.1 RFC2616 document at www.w3.org
Upvotes: -2
Reputation: 99533
For situation 1 there are two options:
200 OK
returning an empty collection.For situation 2, it's really the same. The only potential difference is that if you returned 404
for situation 1, you could choose 410 gone
, as it indicates that a cart was here before, but it's now gone.
Regardless of which you choose, I would recommend you take the same strategy for both situations. E.g.: Either return a 2xx code for both or a 4xx code for both.
If the admin deleted the cart by doing a DELETE
request, then the 404/410 status codes are more appropriate.
Upvotes: 7