I'm working on a server developing REST API.
The structure by now (at least what is needed to know for this question) is that I have a products collection retrievable via GET /products
, GET /products/:id
. I want to be able to edit these products, but I want to be able also to make drafts. This will be useful for save the edits but apply them only when done and make a history of the edits.
I thought that a possible way could be develop this endpoints:
GET /products/:id/drafts
this will retrieve all the drafts made for this product
GET /products/:id/draft
this will retrieve the last non applied draft, if any
POST /products/:id/draft/apply
this will apply the last non applied draft, if any
To this point, all seems fine, but I am struggling finding a good way for handling the creation of the drafts. I thought that it could be POST /products/:id/drafts
but, because of there can be only one draft a time, should this response with 409 Conflict
if is there any non applied draft yet?
So I thought that it could be PATCH /products/:id
, so if there is yet a non applied draft, then it will be edited else it will be created. Could it be done?
Can the PATCH /products/:id
return a representation of the draft (created or edited)?
Is it better the POST
approach described before?
Is there another way that I can't think of?