Neo4j REST API + Extension Points

Neo4j REST API + Extension Points


This blog deals with Neo4j – a standalone server with REST API. The REST request for Neo4j is handled with Extension Points implemented using Jersey framework. The Neo4j server also provides the REST interface that allows all modern platforms and programming languages to interoperate with it. The REST API uses HTTP calls and JSON MediaType, so that it can be used from many languages and platforms. Using REST APIs, we can perform ACID operation successfully in two ways ‑ Fine grained and Generic (using CQL). Please refer to our previous blogs on “Embrace Relationships with Neo4j, R & Java” and “Decipher Neo4J Cypher Query Language (CQL)” for more information on this.

Neo4j can be run in the following two modes:

  • An embedded database in a Java application
  • A standalone Neo4j server via REST

Jersey framework has more features than the JAX-RS Reference Implementation. Jersey provides its own API that extends the JAX-RS toolkit with additional features and utilities to further simplify RESTful service and client development.

Use Case

Let us have the same StackOverflow dataset use case which we had generated in the blog “Embrace Relationships with Neo4j, R & Java”, where you were guided to build the StackOverflow dataset graph store using batch importer 2.0 and load it before Neo4j server gets online. This blog guides you to load all data from the StackOverflow dataset into the Neo4j Server while it is online through REST API calls. For this use case, we will create APIs using the Fine Grained method for creating nodes, relationships, properties and Generic method for retrieval nodes and relationships from graph store.

What we need to do:

  • Download StackOverflow Dataset, Data Manipulation with R, create Nodes & Relationships file with Java.
  • Create a dynamic web project using Jersey Jars.
  • Create Java programs which has APIs to add nodes, relations and execute Cypher Queries.
  • Execute Jersey REST APIs.



  • Install JDK 1.7+.
  • Install Tomcat 7 and configure it with Eclipse.
  • Download Neo4j server:
  • The essential project structure and libs to create the project are given below as a screenshot. Download all the Jersey Jars given here.


Download Stack Overflow Dataset, Data Manipulation with R, Create Nodes & Relationships file with Java

  • Do ignore this section if you are not interested to learn or know R and how the StackOverflow dataset came. I have attached the resulting csv files generated from that blog (“”) here.
  • If you are interested, you can follow the sections given below from the blog “Embrace Relationships with Neo4J, R & Java” to download and install Neo4j and to start Neo4j server web console to perform the use case.


Create a Dynamic Web Project Using Jersey Jars

We have used Eclipse to create dynamic web projects using the jersey jar and its dependent jar files. We have created the following four API’s:

addNode Used to add nodes with properties like id (mandatory), name, score, views
addRelation Used to add relationship between nodes by assigning type from user
getOrCreateNodeById Used to get or create Node by its id as path param (mandatory)
executeCypherQuery used to execute cipher queries and return results as like from Neo4j REST HTTP calls

Create Java programs which has APIs to add nodes, relations and execute Cypher Queries

Run the web application in Tomcat:

  • Before creating war file, make sure Neo4j server is online in the local system by clicking on the link http://localhost:7474/
  • Create a war file “neo4j_extensionpoint” and load it in Tomcat Server.

Execute Jersey REST APIs

Run the below APIs from any browser. You can get response like the snapshot given below.

Add Nodes

Language Node:



Question Node:




Answer Node:



User Node:



Response in browser:


Add Relation



Response in browser:


Get or Create Node


Response in browser:



Response in browser:


Execute CQL Query


Response in browser:



  • Neo4j Server is the best choice for interoperability, safety, and monitoring. Also, being a standalone application, it is safer than the embedded configuration (a potential crash in the client wouldn’t affect the server), and it is easier to monitor. If we choose to use this mode, our application will act as a client of the Neo4j server.
  • Jersey framework is more than JAX-RS Reference Implementation. Jersey also exposes numerous extension APIs so developers may extend Jersey to suit their needs.


5163 Views 3 Views Today