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/167
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/295", "property" : "http://localhost:7474/db/data/relationship/167/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/167", "properties" : "http://localhost:7474/db/data/relationship/167/properties", "type" : "know", "end" : "http://localhost:7474/db/data/node/294", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/2/relationships
Accept:
application/json; charset=UTF-8
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/1", "type" : "LOVES" }
Example response
201:
Created
Content-Type:
application/json; charset=UTF-8
Location:
http://localhost:7474/db/data/relationship/1
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/2", "property" : "http://localhost:7474/db/data/relationship/1/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/1", "properties" : "http://localhost:7474/db/data/relationship/1/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/1", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/12/relationships
Accept:
application/json; charset=UTF-8
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/11", "type" : "LOVES", "data" : { "foo" : "bar" } }
Example response
201:
Created
Content-Type:
application/json; charset=UTF-8
Location:
http://localhost:7474/db/data/relationship/8
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/12", "property" : "http://localhost:7474/db/data/relationship/8/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/8", "properties" : "http://localhost:7474/db/data/relationship/8/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/11", "data" : { "foo" : "bar" } }
Example request
DELETE
http://localhost:7474/db/data/relationship/160
Accept:
application/json; charset=UTF-8
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/163/properties
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
{ "cost" : "high", "since" : "1day" }
Example request
PUT
http://localhost:7474/db/data/relationship/168/properties
Accept:
application/json; charset=UTF-8
Content-Type:
application/json
{ "happy" : false }
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/164/properties/cost
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
"high"
Example request
PUT
http://localhost:7474/db/data/relationship/162/properties/cost
Accept:
application/json; charset=UTF-8
Content-Type:
application/json
"deadly"
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/node/357/relationships/all
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
[ { "start" : "http://localhost:7474/db/data/node/357", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/202", "property" : "http://localhost:7474/db/data/relationship/202/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/202/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/358" }, { "start" : "http://localhost:7474/db/data/node/359", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/203", "property" : "http://localhost:7474/db/data/relationship/203/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/203/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/357" }, { "start" : "http://localhost:7474/db/data/node/357", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/204", "property" : "http://localhost:7474/db/data/relationship/204/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/204/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/360" } ]
Example request
GET
http://localhost:7474/db/data/node/376/relationships/in
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
[ { "start" : "http://localhost:7474/db/data/node/378", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/214", "property" : "http://localhost:7474/db/data/relationship/214/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/214/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/376" } ]
Example request
GET
http://localhost:7474/db/data/node/401/relationships/out
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
[ { "start" : "http://localhost:7474/db/data/node/401", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/228", "property" : "http://localhost:7474/db/data/relationship/228/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/228/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/402" }, { "start" : "http://localhost:7474/db/data/node/401", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/230", "property" : "http://localhost:7474/db/data/relationship/230/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/230/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/404" } ]
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/332/relationships/all/LIKES&HATES
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
[ { "start" : "http://localhost:7474/db/data/node/332", "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/333" }, { "start" : "http://localhost:7474/db/data/node/334", "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/332" }, { "start" : "http://localhost:7474/db/data/node/332", "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/335" } ]
Copyright © 2014 Neo Technology