我试图弄清楚如何最好地布置一组 Restlet API。我有一个用户实体,它可能有标准的 CRUD 操作,非常适合休息,但还有其他的,比如“重置密码”或“终止”。
最好的方法是什么?
这是我的想法:
/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
}
真的是坏主意吗?真的是忍者的主意吗?