Whilst it is a convention in REST APIs that POST
is used to create a resource it doesn't necessarily have to be constrained to this purpose.
Referring back to the definition of POST
in RFC 7231:
The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics. For example, POST is used for the following functions (among others):
- Providing a block of data, such as the fields entered into an HTMl form, to a data-handling process
- Posting a message to a bulletin board, newsgroup, mailing list, blog, or similar group of articles;
- *Creating a new resource that has yet to be identified by the origin server; and *
- Appending data to a resource's existing representation(s).
Clearly creation is only one of those purposes and updating existing resources is also legitimate.
The PUT
operation is not appropriate for your intended operation because again, per RFC, a PUT is supposed to replace the content of the target resource (URL). The same also applies to PATCH but, since it is intended for partial updates of the target resource you can target it to the URL of the collection.
So I think your viable options are:
POST /api/v1/entity/update-status
PATCH /api/v1/entity
Personally, I would choose to go with the PATCH
as I find it semantically more pleasing but the POST
is not wrong. Using PATCH
doesn't gain you anything in terms of communicating an idempotency guarantee to a consumer. Per RFC 5789: "PATCH
is neither safe nor idempotent" which is the same as POST
.