【问题标题】:What is the standard practice to serve a REST API request, based on requester format?根据请求者格式提供 REST API 请求的标准做法是什么?
【发布时间】:2017-09-23 15:20:34
【问题描述】:

在我的 REST API 中,我有一个 /items/ 端点,它返回一个项目列表。

我的 API 的用户可以请求不同格式(json、xml、html)的项目。

提供 json 响应的推荐方式是什么:

  • 创建一个/items.json 端点?
  • 创建一个/items/json 端点?
  • 或者根据用户的请求头Content-Type服务

【问题讨论】:

    标签: json rest api


    【解决方案1】:

    根据Accept 请求标头提供它。这是一种标准做法,称为content type negotiation.

    【讨论】:

      猜你喜欢
      • 2016-11-19
      • 1970-01-01
      • 2022-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      • 2018-05-02
      • 2018-02-14
      相关资源
      最近更新 更多