Relationships are a first class citizen in the Neo4j REST API. They can be accessed either stand-alone or through the nodes they are attached to.
The general pattern to get relationships from a node is:
GET http://localhost:7474/db/data/node/123/relationships/{dir}/{-list|&|types}
Where dir
is one of all
, in
, out
and types
is an ampersand-separated list of types.
See the examples below for more information.
Example request
GET
http://localhost:7474/db/data/relationship/150
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/249", "property" : "http://localhost:7474/db/data/relationship/150/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/150", "properties" : "http://localhost:7474/db/data/relationship/150/properties", "type" : "know", "end" : "http://localhost:7474/db/data/node/248", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/285/relationships
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/284", "type" : "LOVES" }
Example response
201:
Created
Content-Type:
application/json
Location:
http://localhost:7474/db/data/relationship/170
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/285", "property" : "http://localhost:7474/db/data/relationship/170/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/170", "properties" : "http://localhost:7474/db/data/relationship/170/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/284", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/287/relationships
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/286", "type" : "LOVES", "data" : { "foo" : "bar" } }
Example response
201:
Created
Content-Type:
application/json
Location:
http://localhost:7474/db/data/relationship/172
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/287", "property" : "http://localhost:7474/db/data/relationship/172/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/172", "properties" : "http://localhost:7474/db/data/relationship/172/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/286", "data" : { "foo" : "bar" } }
Example request
DELETE
http://localhost:7474/db/data/relationship/156
Accept:
application/json
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/160/properties
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
{ "since" : "1day", "cost" : "high" }
Example request
PUT
http://localhost:7474/db/data/relationship/159/properties
Accept:
application/json
Content-Type:
application/json
{ "happy" : false }
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/157/properties/cost
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
"high"
Example request
PUT
http://localhost:7474/db/data/relationship/158/properties/cost
Accept:
application/json
Content-Type:
application/json
"deadly"
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/node/311/relationships/all
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/311", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/187", "property" : "http://localhost:7474/db/data/relationship/187/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/187/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/312" }, { "start" : "http://localhost:7474/db/data/node/313", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/188", "property" : "http://localhost:7474/db/data/relationship/188/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/188/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/311" }, { "start" : "http://localhost:7474/db/data/node/311", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/189", "property" : "http://localhost:7474/db/data/relationship/189/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/189/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/314" } ]
Example request
GET
http://localhost:7474/db/data/node/321/relationships/in
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/323", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/194", "property" : "http://localhost:7474/db/data/relationship/194/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/194/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/321" } ]
Example request
GET
http://localhost:7474/db/data/node/326/relationships/out
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/326", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/196", "property" : "http://localhost:7474/db/data/relationship/196/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/196/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/327" }, { "start" : "http://localhost:7474/db/data/node/326", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/198", "property" : "http://localhost:7474/db/data/relationship/198/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/198/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/329" } ]
Note that the "&
" needs to be encoded like "%26
" for example when
using cURL from the terminal.
Example request
GET
http://localhost:7474/db/data/node/331/relationships/all/LIKES&HATES
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/331", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/199", "property" : "http://localhost:7474/db/data/relationship/199/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/199/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/332" }, { "start" : "http://localhost:7474/db/data/node/333", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/200", "property" : "http://localhost:7474/db/data/relationship/200/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/200/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/331" }, { "start" : "http://localhost:7474/db/data/node/331", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/201", "property" : "http://localhost:7474/db/data/relationship/201/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/201/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/334" } ]
Copyright © 2013 Neo Technology