RESTful 州特定端点的命名约定

Naming convention for RESTful state specific endpoint

我有以下情况

带有 CRUD 端点的 Headless CMS 使用 /posts/ 限制对经过身份验证的用户 posts 的访问。即 GET 到 /posts returns 所有当前经过身份验证的用户帖子。

我想要一个只有 returns 个 'publish' 帖子的端点,即它们的 publish_at 日期小于当前时间。

我使用的是 /posts/published,但我认为这不是好的做法。

本质上,我希望 public 端点仅提供特定状态的资源。或者这个目标本身就是问题所在?

你所做的一切都很好。所有这些都是处理此问题的有效方法:

GET /posts/published
GET /posts/bystate/published
GET /posts?state=published
GET /published-posts