[As community content, this post reflects the views and opinions of the particular author and does not necessarily reflect the official stance of Neo4j. This article was originally posted by José Álvarez and was used with permission.]Based on “The Neo4j v2.3.0-M01 Manual” manual under 7.1 How to use the REST API from Java, I’ve developed the same example program using Jersey library (2.19). The goal of this example is to use the REST API from Java when auth is required. The Jersey Client API reuses many aspects of the JAX-RS and the Jersey implementation. To utilize the client API, you first need to build an instance of a Client using one of the static ClientBuilder factory methods. Once you have a Client instance you can create a WebTarget from it.
The URI passed to the method as a String is the URI of the targeted web resource that represents a context root of a RESTful application. If there is a resource exposed on the URI (e.g, “http://example.com/rest/resource”), then a WebTarget instance can be used to derive other web targets.
Client client = ClientBuilder.newClient(); WebTarget webTarget = client.target("http://example.com/rest/");
The resourceWebTarget now points to the resource on URI “http://example.com/rest/resource”. In our example program, once the server is started, we’ll check the connection to it. Want to learn more about the REST API from Java? Read the full article here. Get more from José Álvarez on his blog. Ready to get started with graph databases? Click below to get your free copy of O’Reilly’s Graph Databases ebook and start building better apps powered by graph technologies. Get My Free Copy
WebTarget resourceWebTarget = webTarget.path("resource");