对于 collection 资源上的 HTTP GET 请求的 HTTP 响应的负载主体,是否有任何建议或标准?我在 RFC 7230 中找不到任何内容家庭。
Representational state transfer维基百科上的文章指出:
For a collection resource, such as https://api.example.com/collection/, GET retrieves the URIs of the member resources of the collection resource in the response body.
但是没有引用。
对于 application/json
媒体类型,我有时会在响应中看到一组 URI,例如:
["/collection/item1", "/collection/item2", (…), "/collection/itemN"]
我也看到过带有 “links”
键的对象。
最佳答案
我的回答是:更喜欢光响应以获得更好的性能!如果您的端点是这样的,则无需添加(无用的) key ,例如“链接”或“链接”=>“[GET] https://[your domain]/links” - 这样,很明显您会得到一个链接列表响应。 许多库使用相同的响应语法,例如 => response.data.items - 通过这种方式,您将能够重构您的代码以工业化响应检索。
关于json - 收集资源的响应有效负载主体的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55856069/