I am building an application with a REST-based API and have come to the point where I am specifying status codes for each requests.
What status code should i send for
Status Code 304 Not Modified would also make an acceptable response to a duplicate request. This is similar to processing a header of If-None-Match
using an entity tag.
In my opinion, @Piskvor's answer is the more obvious choice to what I perceive is the intent of the original question, but I have an alternative that is also relevant.
If you want to treat a duplicate request as a warning or notification rather than as an error, a response status code of 304
Not Modified and Content-Location
header identifying the existing resource would be just as valid. When the intent is merely to ensure that a resource exists, a duplicate request would not be an error but a confirmation. The request is not wrong, but is simply redundant, and the client can refer to the existing resource.
In other words, the request is good, but since the resource already exists, the server does not need to perform any further processing.