My goal is to make idempotent /create REST API which is implemented as PUT verb.
Idempotent RFC states:
Idempotent methods are distinguished because the request can be
repeated automatically if a communication failure occurs before the
client is able to read the server's response. For example, if a
client sends a PUT request and the underlying connection is closed
before any response is received, then the client can establish a new
connection and retry the idempotent request. It knows that repeating the request will have the same intended effect, even if the original
request succeeded, though the response might differ.
PUT RFC states:
If the target resource does not have a current representation and the PUT successfully creates one, then the origin server MUST inform the
user agent by sending a 201 (Created) response. If the target
resource does have a current representation and that representation
is successfully modified in accordance with the state of the enclosed representation, then the origin server MUST send either a 200 (OK) or a 204 (No Content) response to indicate successful completion of the
request.
Assuming that /create stores the created resource in DB, should it return 201 on first creation and 200 on retried /create? Should retried /create store the same resource in DB all over again to conform with PUT RFC?
PUT /
andPUT /:id
are 2 different resources – Ayush Gupta