Neo4j 手册中的 Jersey 客户端示例
Jersey client examples in Neo4j Manual
我想使用 Jersey 客户端通过 REST 连接 Neo4j 数据库。在 Neo4j 手册中,他们在教程->语言->如何使用 Java 中的 REST API 中有这方面的示例。我想创建一个新节点,然后使用 Cypher 向其添加关系。在 Neo4j 示例 (https://github.com/neo4j/neo4j/blob/2.2.9/community/server-examples/src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java) 中,他们使用 'createNode',但文档表明这仅适用于嵌入式 Neo4j 服务器。
在 RESTful 上下文中调用 createNode() 是否有效?
在您引用的示例中,定义的 createNode
函数 here 只是向 http://localhost:7474/db/data/node
发出 HTTP POST 请求,这将创建一个新节点:
private static URI createNode()
{
final String nodeEntryPointUri = SERVER_ROOT_URI + "node";
// http://localhost:7474/db/data/node
WebResource resource = Client.create()
.resource( nodeEntryPointUri );
// POST {} to the node entry point URI
ClientResponse response = resource.accept( MediaType.APPLICATION_JSON )
.type( MediaType.APPLICATION_JSON )
.entity( "{}" )
.post( ClientResponse.class );
final URI location = response.getLocation();
System.out.println( String.format(
"POST to [%s], status code [%d], location header [%s]",
nodeEntryPointUri, response.getStatus(), location.toString() ) );
response.close();
return location;
}
此函数在示例代码中定义,与createNode
function that is part of the embedded Java API完全不同。
如果您有兴趣使用新的 Neo4j 3.0 版本(当前为 RC),有一个新的 Java 驱动程序支持 Cypher here。
我想使用 Jersey 客户端通过 REST 连接 Neo4j 数据库。在 Neo4j 手册中,他们在教程->语言->如何使用 Java 中的 REST API 中有这方面的示例。我想创建一个新节点,然后使用 Cypher 向其添加关系。在 Neo4j 示例 (https://github.com/neo4j/neo4j/blob/2.2.9/community/server-examples/src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java) 中,他们使用 'createNode',但文档表明这仅适用于嵌入式 Neo4j 服务器。
在 RESTful 上下文中调用 createNode() 是否有效?
在您引用的示例中,定义的 createNode
函数 here 只是向 http://localhost:7474/db/data/node
发出 HTTP POST 请求,这将创建一个新节点:
private static URI createNode()
{
final String nodeEntryPointUri = SERVER_ROOT_URI + "node";
// http://localhost:7474/db/data/node
WebResource resource = Client.create()
.resource( nodeEntryPointUri );
// POST {} to the node entry point URI
ClientResponse response = resource.accept( MediaType.APPLICATION_JSON )
.type( MediaType.APPLICATION_JSON )
.entity( "{}" )
.post( ClientResponse.class );
final URI location = response.getLocation();
System.out.println( String.format(
"POST to [%s], status code [%d], location header [%s]",
nodeEntryPointUri, response.getStatus(), location.toString() ) );
response.close();
return location;
}
此函数在示例代码中定义,与createNode
function that is part of the embedded Java API完全不同。
如果您有兴趣使用新的 Neo4j 3.0 版本(当前为 RC),有一个新的 Java 驱动程序支持 Cypher here。