假設我想設計一個用於管理列表的REST存儲。 列表條目會是這個樣子:設計一個REST資源來管理列表
<listentry>
<position>0</position> <!-- position in the list -->
<data>interesting information</data> <!-- entry data -->
</listentry>
我會設計這樣的資源:
GET /list/ // returns all list entries
GET /list/{position} // returns the list entry at {position}
DELETE /list/{position} // delete list entry at {position}
PUT /list/first // update first list entry
PUT /list/last // update last list entry
PUT /list/{position} // update entry at {position}
POST /list/last // inserts a new list entry at last position
POST /list/first // inserts a new list entry at first position
POST /list/{position} // inserts a new list entry at {position} and moves all
// entries down the list starting from the entry that
// was at {position} before the insertion.
這是合法的REST資源?如果沒有,有沒有辦法設計一個休息資源,以便它可以管理一個列表?
編輯
感謝您輸入它definetly幫助。 我同意nategood和darrel使用第一個和最後一個作爲特殊標識符是完全合法的(另請參見我的question)。當然,我可以在沒有Saintedlama建議的那些魔術標識符的情況下做到這一點,但是這可能會使我無法將這些標識符用於我現在想提出的發佈請求中。
在再次考慮設計時,我想添加兩個額外的功能到我的資源設計建議。
POST /list/{position1}/swap/{position2} // swap the position of two elements
POST /list/{position1}/move/{position2} // move the element at {position1} to
// {position2} and move all entries
// down the list starting from the
// entry that was at {position2}
//possible uses
POST /list/first/swap/last // swap first with last element
POST /list/42/swap/2 // swap element 42 with element 2
POST /list/first/move/42 // move first element to position 42
// you get the idea ...
您怎麼看?
因此,您將保存對列表中管理的資源的引用? 順便說一句,爲消除第一個和最後一個解決方法的好主意,但請參閱我的編輯使用特殊標識符。 – Zounadire 2012-04-08 18:47:33
抱歉關於編輯後期,但有時候想法會增長:P再次強烈建議,我特別喜歡返回句柄來檢查操作狀態的想法。 – Zounadire 2012-04-09 21:33:29