我很困惑我们是否应该创建单独的 API 来获取结果和结果计数,或者我们应该只根据结果 API 中的查询字符串来获取计数。
/api/results/ : Fetches all records
/api/results/?city=1: Fetches all records with city=1
/api/results/?iscount=1: Fetches the count of records i.e. list of cityId and count of record for respective cityId
/api/results/?city=1&iscount=1: Fetch the count of record for cityId=1
或
/api/resultcount/: Fetches the count of records i.e. list of cityId and count of record for respective cityId
/api/resultcount/?city=1: Fetch the count of record for cityId=1
对我来说,查询字符串用于过滤资源,所以我赞成创建单独的 API 来获取计数。意见?
最佳答案
我们不需要创建另一个点来获取计数。相反,我们可以在响应 header 中发送计数详细信息。
它会像下面这样,
/api/results/(GET 方法)
- 这将返回结果。
/api/results/(HEAD method)
- 这只会在响应 header 中返回结果计数。
下面请看link
关于休息 API : Should we have separate API for result and result count?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47906473/