Database Reference
In-Depth Information
be Invoked
//for executing Cypher Query
WebResource resource =
client.resource("http://localhost:7474").path("/db/
data/cypher");
//Define JSON Object and Cypher Query
JSONObject cypher = new JSONObject();
cypher.accumulate("query", "match n return n limit
10");
//Invoke the rest endpoint as JSON request
ClientResponse res =
resource.accept(MediaType.APPLICATION_JSON)
.entity(cypher.toString())
.post(ClientResponse.class);
//Print the response received from the Server
System.out.println(res.getEntity(String.class));
}
7. Now create an object of MyRestClient in your main method and invoke the
createNode() and sendCypher() methods one by one.
8. Now execute the following command to compile and create a build:
$M2_HOME/bin/mvn clean compile install
9. To run your MyRestClient , execute the following Maven command in the
console:
$M2_HOME/bin/mvn exec:java
-Dexec.mainClass="neo4j.rest.client.MyRestClient"
-Dexec.cleanupDaemonThreads=false.
Both the methods createNode() and sendCypher() expose different endpoints for
handling operations on nodes and query data with Cypher. The createNode() method
will print the URI of the newly created node along with its ID /db/data/node/
{Node_ID} and sendCypher() will print the results of the Cypher query on the con-
sole in the JSON format.
Search WWH ::




Custom Search