小编chr*_*lbs的帖子

我应该在RESTful服务中拥有资源的多个视图/端点吗?

假设我正在创建一个RESTful服务来处理我在网上的仓库订单.

  • 我想允许客户创建帐户
  • 我希望客户管理员能够为其办公室中的其他用户创建帐户
  • 我想允许客户用户创建订单
  • 我希望网站管理员能够创建和管理所有客户帐户
  • 我希望网站管理员能够创建和管理所有用户
  • 我希望网站管理员能够创建和管理所有订单

鉴于这些要求.我最初的想法是以这种方式设计端点.

# to request a new customer account
/customers/request {POST}
# create and view customers - limited to admins
/customers {GET, POST}
# view customer info, update a customer
/customers/{customer_id} {GET, PATCH}
# create and view orders for a customer
/customers/{customer_id}/orders {GET, POST}
# view and update order for a customer
/customers/{customer_id}/orders/{order_id} {GET, PATCH}
Run Code Online (Sandbox Code Playgroud)

我非常自信这些道路是有意义的,并遵循一般的宁静想法.但是,我不确定如何处理用户端点.问题是,我希望客户管理员能够创建可以使用其客户帐户创建订单的用户.客户管理员在哪里发布POST以实现此目的?我有几个想法.在这个答案之后,我想到了这一点.

# creation of users always done through this endpoint no matter what the
# authenticated user's …
Run Code Online (Sandbox Code Playgroud)

rest authorization entity-relationship

6
推荐指数
1
解决办法
3029
查看次数

标签 统计

authorization ×1

entity-relationship ×1

rest ×1