【发布时间】:2016-03-02 11:03:21
【问题描述】:
我正在设计一个新的 API,我怀疑它应该是一个单一的 API 还是应该被划分为最终用户类型。
例如我有以下课程
OrderClass
ProductClass
BuyerClass
SupplierClass
并且想要创建允许买家和供应商访问它的 API
我是否创建一个单一的 API,例如
CompanyAPI that uses access tokens (defining roles and types)
/api/order/orderAction [allowed for buyers, suppliers]
/api/order/orderAction2 [allowed for buyers]
/api/order/orderAction3 [allowed for suppliers]
/api/buyer/buyerAction [allowed for buyers, suppliers]
/api/supplier/supplierAction [allowed for suppliers]
/api/product/productAction [allowed for buyers, suppliers]
或两个旨在满足买方或供应商需求的 API?
BuyersAPI
/BuyersAPI/order/orderAction
/BuyersAPI/order/orderAction2
/BuyersAPI/buyer/buyerAction
/BuyersAPI/product/productAction
SuppliersAPI
/SuppliersAPI/order/orderAction
/SuppliersAPI/order/orderAction3
/SuppliersAPI/supplier/supplierAction
/SuppliersAPI/product/productAction
使用两个 API 的主要原因之一是文档,我不希望买家看到供应商正在获取什么信息(至少是它的结构)似乎是合乎逻辑的。
另一方面,拥有两个 API 意味着某些部分将/可能被重复/复制。
【问题讨论】:
标签: api asp.net-web-api api-design