2013-11-03 21 views
3

想象strutured這樣一個簡單的文件管理Web服務:在RESTFul API中,恢復/回滾操作的正確http動詞是什麼?

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 

現在,讓我們說,我想回滾一個文件到以前的任意版本(例如,從版本5比3)。

在視REST風格來看,什麼ROUTE和應該使用什麼動詞對於這種操作的?我應該爲回滾操作創建一個新的動詞嗎?

請記住,在回滾操作中不會刪除任何內容。在內部,服務器只是識別最新的不同版本號。

+0

從RESTful的角度來看,路由並不重要,方法取決於操作是否是冪等的。試圖回滾到與當前版本相同的版本應該什麼也不做或返回一個錯誤? –

+0

@PedroWerneck不應該做任何事情 – Tivie

回答

6

因爲你必須爲每個版本的表示可用,回滾操作應該是冪等,最直接的方法是簡單地做一個PUTdocument/[id]GET document/[id]/revision/[revisionid]內容,爲revisionid你想document/[id]設置爲。

相關問題