【发布时间】:2021-12-01 19:30:03
【问题描述】:
我有一个资源“客户”,我将 REST 端点定义为,
| URI | Function |
| ------------------------------ | ---------------------------------- |
| /apiv1/customers/ | {GET} Fetch all customers |
| /apiv1/customers/{customer-id} | {GET} Fetch details of the customer |
| /apiv1/customers/ | {POST} Add a new customer |
| /apiv1/customers/{customer-id} | {PUT} Update a customer |
现在,我还要设计一些非 CRUD 操作,比如
- 按支付金额获取前 5 位客户
- 获取最后 3 位客户
- 等
如何为上述操作设计 URI?
我的看法是引入一个新的控制器,每个函数都有一个单独的端点,例如:
- /apiv1/customers/fetch-top-5
- /apiv1/customers/fetch-last-3
我仍然对上述方法没有信心。另外,如果我想参数化这些操作,比如 fetch-top-n 客户,该怎么办
【问题讨论】: