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/9
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/40", "property" : "http://localhost:7474/db/data/relationship/9/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/9", "properties" : "http://localhost:7474/db/data/relationship/9/properties", "type" : "know", "end" : "http://localhost:7474/db/data/node/39", "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/2
Accept:
application/json; charset=UTF-8
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/5/properties
Accept:
application/json; charset=UTF-8
Example response
200:
OK
Content-Type:
application/json; charset=UTF-8
{ "since" : "1day", "cost" : "high" }
Example request
PUT
http://localhost:7474/db/data/relationship/10/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/6/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/4/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/137/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/137", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/95", "property" : "http://localhost:7474/db/data/relationship/95/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/95/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/138" }, { "start" : "http://localhost:7474/db/data/node/139", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/96", "property" : "http://localhost:7474/db/data/relationship/96/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/96/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/137" }, { "start" : "http://localhost:7474/db/data/node/137", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/97", "property" : "http://localhost:7474/db/data/relationship/97/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/97/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/140" } ]
Example request
GET
http://localhost:7474/db/data/node/156/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/158", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/107", "property" : "http://localhost:7474/db/data/relationship/107/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/107/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/156" } ]
Example request
GET
http://localhost:7474/db/data/node/181/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/181", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/121", "property" : "http://localhost:7474/db/data/relationship/121/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/121/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/182" }, { "start" : "http://localhost:7474/db/data/node/181", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/123", "property" : "http://localhost:7474/db/data/relationship/123/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/123/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/184" } ]
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/112/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/112", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/80", "property" : "http://localhost:7474/db/data/relationship/80/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/80/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/113" }, { "start" : "http://localhost:7474/db/data/node/114", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/81", "property" : "http://localhost:7474/db/data/relationship/81/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/81/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/112" }, { "start" : "http://localhost:7474/db/data/node/112", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/82", "property" : "http://localhost:7474/db/data/relationship/82/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/82/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/115" } ]
Copyright © 2013 Neo Technology