【发布时间】:2021-12-01 18:44:29
【问题描述】:
我怀疑在使用 json api 标准和后端和前端之间的通信时有什么更好的选择。我只需要作者关联中的一个属性-“用户名”和其他内容应该为获取此内容的用户隐藏
案例a)
data: [
{
id: „100”,
type: „resource1”,
attributes: {…},
relationships: {author: {data: {id: „10”, type: „author”}}}
}
],
included: [
{
id: „10”,
type: „author”,
attributes: {username: „name”},
relationships: {resources1: {data: [{id: „100”, type: „resource1”}]}}
}
]
案例 b)
data: [
{
id: „100”,
type: „resource1”,
attributes: {authorName: „name”, …},
relationships: {author: {data: {id: „10”, type: „author”}}}
}
],
included: []
案例 a) 看起来是语义化的,但在有效负载中提供了更多信息 案例 b)更快地从作者那里得到我想要的东西(一个属性“用户名”,这是在附加属性中添加的:“作者名”),所以也不需要在前端进行关联。
有什么更好的做法,为什么?
【问题讨论】:
标签: json-api