简体   繁体   English

在 REST API 设计中获取 /users/:id/posts 或 /posts/user/:id 端点中的用户帖子?

[英]Get user's posts in /users/:id/posts or in /posts/user/:id endpoint in REST API design?

如果我们按特定用户 ID 搜索帖子列表,这两个端点中哪一个是按用户 ID 获取帖子列表的正确方法?

1.2. 1.2. Collection and Sub-collection Resources馆藏和子馆藏资源

A resource may contain sub-collection resources also.一个资源也可能包含子集合资源。

For example, sub-collection resource “accounts” of a particular “customer” can be identified using the URN “/customers/{customerId}/accounts” (in a banking domain).例如,可以使用 URN“/customers/{customerId}/accounts”(在银行域中)识别特定“客户”的子集合资源“帐户”。

Similarly, a singleton resource “account” inside the sub-collection resource “accounts” can be identified as follows: “/customers/{customerId}/accounts/{accountId}“.类似地,子集合资源“accounts”中的单例资源“account”可以标识如下:“/customers/{customerId}/accounts/{accountId}”。

Then /users/:id/posts is the recommended way.那么/users/:id/posts是推荐的方式。

You can read more in: https://restfulapi.net/resource-naming/您可以在以下位置阅读更多信息: https : //restfulapi.net/resource-naming/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM