Imagine a simple document management webservice strutured like this:
document/
GET -> retrieves all documents
POST -> creates a new document
document/[id]
GET -> retrieves the "latest" revision of document specified by ID
POST -> creates a new revision of the document
document/[id]/revision
GET -> retrieves all revisions of the document
POST -> Alias to POST->document/[id]
document/[id]/revision/[revisionID]
GET -> retrieves the specified revision of the document
Now, let's say I want to rollback a document to a previous arbitrary revision (for instance, from revision 5 to 3).
In a RESTful point of view, what ROUTE and what VERB should be used for this kind of operation? Should I create a new verb for rollback operations?
Keep in mind that in a rollback operation nothing is deleted. Internally, the server just recognises a different revision number as the latest.
Since you have the representations for each revision available, and the rollback operation should be idempotent, the most straightforward approach would be simply doing a PUT
to document/[id]
with the contents of GET document/[id]/revision/[revisionid]
, for the revisionid
you want document/[id]
to be set to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With