Database Reference
In-Depth Information
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
5. Next we will define a new method in MyRestClient.java for adding a new
node:
public class MyRestClient {
public void createNode(){
//Create a REST Client
Client client = Client.create();
//Define a resource (REST Endpoint) which needs
to be Invoked for creating a Node
WebResource resource =
client.resource("http://localhost:7474").path("/db/
data/node");
//Define properties for the node.
JSONObject node = new JSONObject();
node.append("Name", "John");
//Invoke the rest endpoint as JSON request
ClientResponse res =
resource.accept(MediaType.APPLICATION_JSON)
.entity(node.toString())
.post(ClientResponse.class);
//Print the URI of the new Node
System.out.println("URI of New Node = " +
res.getLocation());
}
}
6. Next, we will define another method in MyRestClient.java , just above the
closing braces of the class ( } ), and add the following code to query the database
using Cypher:
public void sendCypher() {
//Create a REST Client
Client client = Client.create();
//Define a resource (REST Endpoint) which needs to
Search WWH ::




Custom Search