api - 何时选择关联而非查询

标签 api rest http

假设我正在为狗及其主人制作一个 RESTful API。我有一个狗端点 /dogs/123 和所有者端点 /owner/321

如果我想列出主人的狗,我可以获取 /owner/321/dogs/dogs?owner_id=321

在哪种情况下哪个更可取?我应该支持这两个选项吗?

最佳答案

如本 best practices reference card 中所述:

You should leverage the hierarchical nature of the URL to imply structure (aggregation or compositon)

你可以选择:

GET /owners/321/dogs

关于api - 何时选择关联而非查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33035556/

相关文章:

json - REST API - 使用 "Accept: application/json"HTTP header

java - 请求不使用 PersistentCookieStore 中保存的 cookie

java - 服务器长时间保持连接时http请求会超时吗?

node.js - Module parse failed top-level-await 实验未启用

php - PHP 的 oAuth 签名创建问题(将照片集发布到 Tumblr)

c# - 如何将 SAML XML token 字符串转换为 SecurityToken 或 ClaimsPrincipal 实例?

java - 在 Spring 中使用 Cookie 对 Restful 服务进行身份验证

apache - 是否可以将我网站的特定页面(使用 https)重定向到 http?

javascript - 基本身份验证无法使用 JavaScript

api - Elastic Search Scroll API 异步执行