【问题标题】:In neo4j can I get a less verbose REST api response在 neo4j 中,我可以获得不那么冗长的 REST api 响应吗
【发布时间】:2014-06-18 09:18:21
【问题描述】:
  1. 有没有办法在 neo4j 中获得不那么冗长的 rest api 响应, 也许只有节点数据?在每个请求上发送所有额外的数据似乎有点浪费带宽。

  2. 为什么所有的元数据都包含在响应中?例如,基本 api url 在整个过程中重复,一旦你 拥有节点 ID,可以可靠地预测所有属性的 url 比如自我、属性、关系等等……它们看起来不像是非常不稳定的 url。


{
      "extensions" : {
      },
      "paged_traverse" : "http://localhost:7474/db/data/node/183/paged/traverse/{returnType}{?pageSize,leaseTime}",
      "outgoing_relationships" : "http://localhost:7474/db/data/node/183/relationships/out",
      "traverse" : "http://localhost:7474/db/data/node/183/traverse/{returnType}",
      "all_typed_relationships" : "http://localhost:7474/db/data/node/183/relationships/all/{-list|&|types}",
      "all_relationships" : "http://localhost:7474/db/data/node/183/relationships/all",
      "property" : "http://localhost:7474/db/data/node/183/properties/{key}",
      "self" : "http://localhost:7474/db/data/node/183",
      "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/183/relationships/out/{-list|&|types}",
      "properties" : "http://localhost:7474/db/data/node/183/properties",
      "incoming_relationships" : "http://localhost:7474/db/data/node/183/relationships/in",
      "incoming_typed_relationships" : "http://localhost:7474/db/data/node/183/relationships/in/{-list|&|types}",
      "create_relationship" : "http://localhost:7474/db/data/node/183/relationships",
      "data" : {
      }
    }

【问题讨论】:

  • 是的,我认为它过于冗长。出于这个原因,我尽量避免返回节点和关系本身。

标签: neo4j


【解决方案1】:

发送的信息是 HTTP API 中内置的 REST 发现机制的一部分。更改此值会导致许多现有客户端软件损坏,因为这些值被用作“有根据的猜测”的替代品。

现有服务器无法生成此数据,但如果您只需要它的节点属性,http://localhost:7474/db/data/node/183/properties URI 只会为您提供一组简单的键值对。

确实,URI 本身似乎并不特别不稳定。但是,如果这些 URI 在未来的服务器版本中发生更改,则遵循发现机制的客户端软件将受到保护,不会发生这种更改。

【讨论】:

  • 好吧,如果你只是允许一个额外的 HTTP 请求参数来请求更短的结果,你肯定不会破坏任何东西。
  • 我同意流程。如果您对数据进行如此多的处理,这是一个主要问题。
【解决方案2】:

您始终可以编写自己的server plugin,它以您想要的格式提供数据。

【讨论】:

    【解决方案3】:

    如果您使用 Cypher,您可以通过不返回完整节点/rels 而是返回您需要的值来减少详细程度,请参阅 http://docs.neo4j.org/chunked/snapshot/rest-api-cypher.html

    【讨论】:

    • 我好像记得有人告诉我应该使用事务提交端点来减少冗长,是这样吗?
    【解决方案4】:

    我在寻找同样的东西时遇到了这个未回答的问题,所以我知道我可以通过插入我对这个问题的解决方案来帮助 某人Trying to interpret the Node-Neo4j API

    【讨论】:

      猜你喜欢
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 2015-10-31
      • 2021-08-12
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      相关资源
      最近更新 更多