【发布时间】:2014-11-14 10:18:36
【问题描述】:
我的 API 中开始出现 RPC 样式动词时遇到了一些问题。
我的问题是:可以在 Restful API 中使用“提交”、“SendForApproval”、“接受”和“拒绝”这些动词吗?这是否违反了 Restful 原则?命名这些操作的最佳做法是什么?
我们的商业案例: 我有一个命令。它以“预购”状态开始。然后我想打电话来根据我们的业务逻辑验证订单。根据验证结果,然后我将其提交或发送以供批准。审批流程在我们的解决方案外部发生,然后当它通过审批流程时,调用 Api 以将订单标记为已接受或已拒绝。
除了简单地更新状态之外,还有更多事情要做 - 我们将内容发送到打印队列、分离跟踪文档等。
所以我们定义的URI是
https://api.site.com/orders // A list of orders
https://api.site.com/orders/{orderId} // An order
https://api.site.com/orders/{orderId}/ValidationErrors // Get a list of validation results
https://api.site.com/orders/{orderId}/Submit // Submit the order for processing
https://api.site.com/orders/{orderId}/SendForApproval // Send to supervisor
https://api.site.com/orders/{orderId}/Accept // Supervisor Accepts the order for processing
https://api.site.com/orders/{orderId}/Reject // Supervisor can Reject the order
【问题讨论】:
标签: rest asp.net-web-api2