Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a RESTFul API, what's the correct http verb to a revert / rollback action?

Tags:

rest

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.

like image 599
Tivie Avatar asked Mar 22 '23 19:03

Tivie


1 Answers

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.

like image 88
Pedro Werneck Avatar answered Apr 06 '23 04:04

Pedro Werneck