Skip to content

Instantly share code, notes, and snippets.

@onlyshk
Created May 14, 2012 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlyshk/2692802 to your computer and use it in GitHub Desktop.
Save onlyshk/2692802 to your computer and use it in GitHub Desktop.
API

neo4j http api

Node api:

Create empty node:

httpc:request(post, {"http://127.0.0.1:7474/db/data/node", ["application/json"], "application/json", []}, [], []). 

Create node with some properties

httpc:request(post, {"http://127.0.0.1:7474/db/data/node", ["application/json"], "application/json", "{\"name\":\"Sasha\"}"}, [], []).

Get node

httpc:request("http://127.0.0.1:7474/db/data/node/4"). 
  • Where 4 - nodeId

Set properties on node

httpc:request(put, {"http://127.0.0.1:7474/db/data/node/2/properties", ["application/json"], "application/json", "{\"name\":\"Sasha5\"}"}, [], []).

Where:

  • 2 - node id *"{\"name\":\"Sasha5\"}" - set new property value

Delete properties in node

httpc:request(delete, {"http://127.0.0.1:7474/db/data/node/2/properties",[]}, [], []).

Get property on node

httpc:request(get, {"http://127.0.0.1:7474/db/data/node/3/properties/name",[]}, [], []).

Where:

  • 3 - nodeId
  • name - properties key

Delete node

httpc:request(delete, {"http://127.0.0.1:7474/db/data/node/2",[]}, [], []).

Where:

  • 2 - nodeId

Relationships

Create relationship

httpc:request(post, {"http://127.0.0.1:7474/db/data/node/5/relationships", ["application/json"], "application/json", "{\"to\": \"http://localhost:7474/db/data/node/4\", \"type\": \"follow\"}"}, [], []). 

Where:

  • 5 - from relationship
  • type - type of relation
  • to - to relationship

Delete relationship

httpc:request(delete, {"http://127.0.0.1:7474/db/data/relationships/5", []}, [], []). 

Where:

  • 5 - relation id

Batch

Create more node for 1 time

If we want to make more that 1 node (or other entities) for 1 http request we must use batch request:

Example request

[ {
  "method" : "PUT",
  "to" : "/node/77/properties",
  "body" : {
    "age" : 1
  },
  "id" : 0
}, {
  "method" : "GET",
  "to" : "/node/77",
  "id" : 1
}, {
  "method" : "POST",
  "to" : "/node",
  "body" : {
    "age" : 1
  },
  "id" : 2
}, {
  "method" : "POST",
  "to" : "/node",
  "body" : {
    "age" : 1
  },
  "id" : 3
} ]

Request in erlang

httpc:request(post, {"http://127.0.0.1:7474/db/data/batch/", ["application/json"], "application/json", "[{\"method\" : \"POST\",\"to\" : \"/node\", \"body\" : {\"name\" : \"User1\"},\"id\" : 0},{\"method\" : \"POST\",\"to\" : \"/node\", \"body\" : {\"name\" : \"User2\"},\"id\" : 1}]"}, [], []). 

Links

http://components.neo4j.org/neo4j-server/1.3.M02/rest.html#Create_node_with_properties

http://www.hacksparrow.com/neo4j-tutorial-rest-api.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment