简体   繁体   English

Neo4j手册中的Jersey客户示例

[英]Jersey client examples in Neo4j Manual

I want to use the Jersey client to connect via REST with a Neo4j database. 我想使用Jersey客户端通过REST与Neo4j数据库连接。 In the Neo4j manual they have examples of this in Tutorials->Languages->How to use the REST API from Java. 在Neo4j手册中,它们在Tutorials-> Languages-> How to use the REST API from Java中提供了示例。 I want to create a new node and then use Cypher to add relationships to it. 我想创建一个新节点,然后使用Cypher向其添加关系。 In the Neo4j example ( https://github.com/neo4j/neo4j/blob/2.2.9/community/server-examples/src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java ) they use 'createNode', but the documentation suggests that that is only available using an embedded Neo4j server. 在Neo4j示例( https://github.com/neo4j/neo4j/blob/2.2.9/community/server-examples/src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java )中,他们使用“ createNode”,但文档建议仅在嵌入式Neo4j服务器上可用。

Does calling createNode() work in a RESTful context? 调用createNode()是否可以在RESTful上下文中工作?

In the example that you reference, the createNode function as defined here is simply making an HTTP POST request to http://localhost:7474/db/data/node which will create a new node: 在您引用的示例中, 此处定义的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;
}

This function is defined in the sample code and is completely different than the createNode function that is part of the embedded Java API . 此函数在示例代码中定义,并且与嵌入式Java API中createNode函数完全不同。

If you are interested in working with the new Neo4j 3.0 version (currently RC) there is a new Java driver that supports Cypher here . 如果您对使用新的Neo4j 3.0版本(当前为RC)感兴趣,可以在此处找到支持Cypher的新Java驱动程序。

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

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