如何存储文档的树状结构(json),并通过RESTful url访问每个父节点或子节点



例如,导航到localhost/root/parent1/child3/node将显示一个json文档,pathlocalhost/root/parent2/将显示一个json文档,其中包含指向其子['localhost/root/parent2/child1', 'localhost/root/parent2/child2/', ...]的链接数组

我需要一种方法来快速遍历所有节点,做过滤器,如localhost/root?date='05/27/2014',它将返回文档树,其中节点具有与所提供的日期匹配的修改日期。因此localhost/root?date='05/27/2014'/parent2/将只列出与05/27/2014修改日期匹配的子节点

图形数据库是最好的这个或MongoDB?这看起来不像是一个过度定制的特性,它几乎就像一个REST HATEOAS链接关系。

每个节点的基本url:

`/api/tree/{id}`
`/api/tree/id:{id}` - if you want to use alternative syntaxes as well

另一个url应该是这样的,但没有必要使用这个,最好使用链接关系来遍历树。

/api/v1/tree/rootNode/level1Child/level2Child/level3Child/...

响应的数据部分应该是这样的:

{
    id: "sthfh3rfasvdfn",
    name: "rootNode",
    childNodes: [
        {
            id: "svfwgf3z4ervd",
            name: "level1Child",
            childNodes: [
                {
                    id: "bvniw3k2rn238dgi",
                    name: "level2Child",
                    childNodes: [
                        {
                            ...
                        }
                    ]
                }
            ]
        }
    ]
}

或者您可以使用索引来代替名称。

超媒体响应的控制器部分应包含IANA链接关系:

  • 实际节点的self
  • 父节点upcollection
  • 每个子节点的item
  • first, last, next, previous子节点分页

尝试使用超媒体json格式的响应,例如json - ld或HAL+ json。

最新更新