我有一个指向MongoDB的Python-Eve-API,它能够按照docs中的描述序列化嵌入资源。在
在我的例子中,请求http://127.0.0.1:5000/sectors
会导致以下响应(不是序列化嵌入的资源):
{
"_items": [
{
"mflow_fluid": 0.23,
"_id": "562692d055c40f709ce289d5",
"inlet_top": true,
"inlet_temp": 353,
"_etag": "53c3d9b10fc2bdcc4f68c7ed07d3ba13f57ca252",
"_created": "Tue, 20 Oct 2015 19:15:28 GMT",
"_updated": "Tue, 20 Oct 2015 19:15:28 GMT",
"name": "sector_heating",
"_links": {
"self": {
"title": "Sector",
"href": "sectors/562692d055c40f709ce289d5"
}
},
"angle_deg": 180,
"fluid": "562692d055c40f709ce289d4"
},
{
"mflow_fluid": 0.46,
"_id": "562692d055c40f709ce289d6",
"inlet_top": true,
"inlet_temp": 283,
"_etag": "0aaf153ff7417cde03bacb0601c5ee244d173cfe",
"_created": "Tue, 20 Oct 2015 19:15:28 GMT",
"_updated": "Tue, 20 Oct 2015 19:15:28 GMT",
"name": "sector_cooling",
"_links": {
"self": {
"title": "Sector",
"href": "sectors/562692d055c40f709ce289d6"
}
},
"angle_deg": 180,
"fluid": "562692d055c40f709ce289d4"
}
],
"_meta": {
"page": 1,
"max_results": 25,
"total": 2
},
"_links": {
"self": {
"title": "sectors",
"href": "sectors"
},
"parent": {
"title": "home",
"href": "/"
}
}
}
如您所见,键fluid
包含一个嵌入的资源,可以使用http://127.0.0.1:5000/sectors?embedded={"fluid":1}
之类的请求对其进行序列化,并给出以下响应:
键fluid
的嵌入资源按需序列化。但是,此资源包含另一个嵌入资源,该资源位于fluid
的{component
。在
有没有一种方法可以“递归地”序列化所有嵌入的资源,以获得一个完全序列化的资源作为响应?在
我试图做一些类似http://127.0.0.1:5000/sectors?embedded={"fluid":1 "fluid.composition.component":1}
的操作,结果得到了400个响应:
{
"_error": {
"code": 400,
"message": "Unable to parse `embedded` clause"
},
"_status": "ERR"
}
恐怕目前还不支持。嵌入式资源序列化当前支持嵌套资源,但有一些limitations:
相关问题 更多 >
编程相关推荐