我在想如何最好地佈局一組Restlet API。 我有一個用戶實體,它可能有標準的CRUD操作,很適合休息,但也有其他的,比如「重置密碼」或「終止」。Restlet在一個實體上執行多個操作
最好的方法是什麼?
這裏是我的想法是:
/1.0/user/update //perhaps this would just be a PUT on /1.0/user
/1.0/user/resetPassword //This would reset the password, but also send an email.
/1.0/user/terminate //This might do some additional cleanup
然後我會作出UserResource,將真正重視這樣
/1.0/user/{actionType}
而且處理代碼可能是這樣的(僞):
action = request.getAttributes().get("actionType");
if (action == "update") {
do update
} elif (action == "resetpassword") {
do resetpassword
} elif (action == "terminate") {
do terminate
}
非常糟糕的主意?真的忍者的想法?
'/1.0/user?op = resetPassword'遠離RESTful,對於'/1.0/resetPassword?userId = xyzzy'也一樣都不是RESTful,它們是RPC over HTTP – 2011-12-13 22:01:10
@JarrodRoberson對不起,我恭敬地不同意。如果客戶端看到
,然後去構建一個GET /1.0/user?op=resetPassword作爲結果,那麼它就像你將要得到的那樣遠離RPC。 RPC和REST的格式和結構都不是*,而是都在客戶端找出URI,以及它們是在客戶端硬編碼還是在運行時發現。 – mogsie 2012-01-10 20:09:20