休息 API : Should we have separate API for result and result count?

标签 rest api restful-architecture api-design

我很困惑我们是否应该创建单独的 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/

相关文章:

java - 如果我使用 JAX-RS 来实现 Web 应用程序(相对于 Web 服务),您怎么看?

java - 调用网络服务更好还是重写代码更好?

json - 为什么在具有 KAA 的端点客户端中得到 200 的响应但不显示消息正文

rest - 有关使用 REST 和 Backbone 的身份验证工作流程的问题

javascript - Rest API 显示 [object Object] 而不是数组对象

python - 使用三引号将变量值添加到字符串中

api - 我无法使用 RTCVideoRenderer 镜像属性。如何解决这个问题?

rest - 资源是否始终位于 REST 中的服务器上?

api - 维基百科 API : search for famous people

php - 如何始终将属性附加到 Laravel Eloquent 模型?