HTTP Get with 204 No Content: Is that normal
Solution 1:
204 No Content
The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.
According to the RFC part for the status code 204, it seems to me a valid choice for a GET request.
A 404 Not Found
, 200 OK
with empty body and 204 No Content
have completely different meaning, sometimes we can't use proper status code but bend the rules and they will come back to bite you one day or later. So, if you can use proper status code, use it!
I think the choice of GET or POST is very personal as both of them will do the work but I would recommend you to keep a POST instead of a GET, for two reasons:
- You want the other part (the servlet if I understand correctly) to perform an action not retrieve some data from it.
- By default GET requests are cacheable if there are no parameters present in the URL, a POST is not.
Solution 2:
I use GET/204 with a RESTful collection that is a positional array of known fixed length but with holes.
GET /items
200: ["a", "b", null]
GET /items/0
200: "a"
GET /items/1
200: "b"
GET /items/2
204:
GET /items/3
404: Not Found