REST API:我们是否应该为结果和结果计数分别使用API ?

问题描述 投票:1回答:1

我很困惑我们是否应该为获取结果和结果计数创建单独的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来获取计数。意见?

rest api restful-architecture api-design
1个回答
1
投票

我们不需要为获取计数创建另一个点。相反,我们可以在响应头中发送计数详细信息。

它将类似于下面,

/ api / results /(GET方法) - 这将返回结果。

/ api / results /(HEAD方法) - 这将只返回响应头中的结果计数。

请看下面的链接What’s the best RESTful method to return total number of items in an object?

© www.soinside.com 2019 - 2024. All rights reserved.