Over a million developers have joined DZone.

Neo4jD - .NET Client for a Neo4j Graph Database - Part 1

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

Last couple of days I was working on a small light weight .NET client for Neo4j. The client framework is still in progress. This post gives some existing Api’s in Neo4jD to perform basic graph operations. In Neo4j two main entities are Nodes and Relationships. So my initial focus for the client library is to deal with Node and Relationship. The communication between client and Neo4j server is in REST Api’s and the response from the server is in json format.

Let’s go through some of the Neo4j REST Api’s and the equivalent api’s in Neo4jD, you can see more details of Neo4j RestAPi’s here.

The below table will show how to call Neo4j REST Api directly from an application and the right hand will show how to do the same operation using Neo4jD client.

 

Neo4j Api Equivalent Neo4jD Api
Create Node  

POST http://localhost:7474/db/data/node
Accept: application/json
Content-Type: application/json
{"FirstName" : "Sony"}

Response (click here to see full response)

{
  "outgoing_relationships" : "
http://localhost:7474/db/data/node/……..,
  "data" : {
    "foo" : "bar"
  },…..

}

Node sony=new Node();
sony.AddProperty(“FirstName”,”Sony”);
sony.Create();
Get Node by ID  
GET http://localhost:7474/db/data/node/3

 

Response (click here to see full response)

{
  "outgoing_relationships" :
http://localhost:7474/db/……….,
  "data" : {
    "FirstName" : "Sony"
  },
  "traverse" :
http://localhost:7474/db/data. . .{returnType},
..........
}

 

Node sony=Node.Get(1);
Assert.AreEqual(“Sony”, sony.GetProperty(“FirstName”);

The Neo4jD will create a Rest request to fetch the Node with Id 1 and parse the json response and set the properties and required field.

Create Relationship between two Nodes  

POST http://localhost:7474/db/data/node/1/relationships
Accept: application/json
Content-Type: application/json
{"to" :
http://localhost:7474/db/data/node/2, "type" : "wife"}

Response

(click here to see full response)

Node sony=Node.Get(1); //Get an existing node
//Create a new node
Node viji=new Node();
viji.AddProperty(“FirstName”,”Viji”);
viji.Create();

RelationShip relation=sony.CreateRelationshipTo(viji, “wife”);

 

Client lib is still missing some basic features and I am working on it.

The next important part of the library is Graph traversing. Neo4j supports REST api, Cypher and Germlin for Graph traversing. I am currently writing a query creator for Germlin. So the initial version of Neo4jD will only support Germlin.

If any one wants to join the project feels free to send me a personal mail or add a comment. You all can have a look at the code in Git.


Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Sony Arouje, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}