【发布时间】:2015-02-08 22:05:57
【问题描述】:
我正在使用支持 HATEOAS 的 Spring Data REST。我是这个范式的新手。
在来自我的 RESTful Web 服务的 GET 响应中,我经常在名为 _embedded 的节点内收到结果。
我想知道:_embedded 节点是干什么用的?它是 REST 规范的一部分吗?还是 HATEOAS 规范的一部分?还是特定于它们的 Spring 实现?
这是GET http://localhost:8080/mywebservice/features 的 JSON 结果示例:
{
"_links":
{
"search": { "href": "http://localhost:8080/mywebservice/features/search" }
},
"_embedded":
{
"features":
[
{
"feature": "GROUND",
"name": "Terreno",
"data_type": "String",
"_links":
{
"self" : { "href": "http://localhost:8080/mywebservice/features/GROUND" },
"values": { "href": "http://localhost:8080/mywebservice/features/GROUND }
}
},
...
]
}
}
我注意到我在响应中几乎总是有_embedded 节点:如果我请求一个集合,但即使通过搜索请求单个资源(例如使用GET http://localhost:8080/mywebservice/persons/search/findByEmail?email=example@example@.com)。
只有当请求是针对特定资源时,我才得到 _embedded 节点,例如在执行 GET http://localhost:8080/mywebservice/features/GROUND 时。
【问题讨论】:
-
根据HAL draft RFC
_embedded包含嵌入资源
标签: json spring rest hateoas spring-hateoas