Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

· Java Zone
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

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.


Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.

Topics:

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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}