繁体   English   中英

Neo4j手册中的Jersey客户示例

[英]Jersey client examples in Neo4j Manual

我想使用Jersey客户端通过REST与Neo4j数据库连接。 在Neo4j手册中,它们在Tutorials-> Languages-> How to use the REST API from Java中提供了示例。 我想创建一个新节点,然后使用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服务器上可用。

调用createNode()是否可以在RESTful上下文中工作?

在您引用的示例中, 此处定义的createNode函数只是向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;
}

此函数在示例代码中定义,并且与嵌入式Java API中createNode函数完全不同。

如果您对使用新的Neo4j 3.0版本(当前为RC)感兴趣,可以在此处找到支持Cypher的新Java驱动程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM