我有一个标签系统:
所以它们可以嵌套(最大深度为3)
例如:
我有一些有标签的资源。
我的终点很少:
/api/tags
{
"items": [
{
"_links": {
"self": {
"href": "/api/tags/1"
}
},
"id": 1,
"name": "Food",
"_embedded": {
"children": [
{
"_links": {
"self": {
"href": "/api/tags/4"
}
},
"id": 4,
"name": "Restaurant",
"_embedded": {
"children": []
}
},
{
"_links": {
"self": {
"href": "/api/tags/5"
}
},
"id": 5,
"name": "Fast food",
"_embedded": {
"children": []
}
}
]
}
},
{
"_links": {
"self": {
"href": "/api/tags/2"
}
},
"id": 2,
"name": "Medicine",
"_embedded": {
"children": []
}
},
{
"_links": {
"self": {
"href": "/api/tags/3"
}
},
"id": 3,
"name": "Entertainment",
"_embedded": {
"children": []
}
}
]
}
/api/place/1
{
"id": 1,
"name": "FooBar Arena",
"_embedded": {
"tags": [
{
"_links": {
"self": {
"href": "/api/tags/1"
}
},
"id": 1,
"name": "Food"
},
{
"_links": {
"self": {
"href": "/api/tags/2"
}
},
"id": 2,
"name": "Medicine"
}
]
}
}
所以我不希望标签在被列为嵌入式资源本身时具有嵌入式资源,但是由于不包括嵌入式子级,我最终得到了具有相同SELF链接的相同数据的两种不同表示,客户端应该如何比较那些?比较SELF链接可以工作,但一个表示缺少children
答案 0 :(得分:1)
我相信一个好的HAL客户端不认为_embedded
是表示的一部分。一个好的HAL客户端只需使用_embedded
中的值来加热缓存。 _embedded
中显示的项目仍应显示在_links
中。
因此,只要每个资源的标记都显示在_links
中,就不需要多次嵌入相同的资源。