19.8. Relationships
- Get Relationship by ID
- Create relationship
- Create a relationship with properties
- Delete relationship
- Get all properties on a relationship
- Set all properties on a relationship
- Get single property on a relationship
- Set single property on a relationship
- Get all relationships
- Get incoming relationships
- Get outgoing relationships
- Get typed relationships
- Get relationships on a node without relationships
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.
Get Relationship by ID
Example request
-
GET
http://localhost:7474/db/data/relationship/56
-
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/133", "property" : "http://localhost:7474/db/data/relationship/56/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/56", "properties" : "http://localhost:7474/db/data/relationship/56/properties", "type" : "know", "end" : "http://localhost:7474/db/data/node/132", "data" : { } }
Create relationship
Upon successful creation of a relationship, the new relationship is returned.
Example request
-
POST
http://localhost:7474/db/data/node/10/relationships
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/9", "type" : "LOVES" }
Example response
-
201:
Created
-
Content-Type:
application/json; charset=UTF-8
-
Location:
http://localhost:7474/db/data/relationship/3
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/10", "property" : "http://localhost:7474/db/data/relationship/3/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/3", "properties" : "http://localhost:7474/db/data/relationship/3/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/9", "data" : { } }
Create a relationship with properties
Upon successful creation of a relationship, the new relationship is returned.
Example request
-
POST
http://localhost:7474/db/data/node/20/relationships
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/19", "type" : "LOVES", "data" : { "foo" : "bar" } }
Example response
-
201:
Created
-
Content-Type:
application/json; charset=UTF-8
-
Location:
http://localhost:7474/db/data/relationship/10
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/20", "property" : "http://localhost:7474/db/data/relationship/10/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/10", "properties" : "http://localhost:7474/db/data/relationship/10/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/19", "data" : { "foo" : "bar" } }
Delete relationship
Example request
-
DELETE
http://localhost:7474/db/data/relationship/49
-
Accept:
application/json; charset=UTF-8
Example response
-
204:
No Content
Get all properties on a relationship
Example request
-
GET
http://localhost:7474/db/data/relationship/52/properties
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
{ "cost" : "high", "since" : "1day" }
Set all properties on a relationship
Example request
-
PUT
http://localhost:7474/db/data/relationship/57/properties
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
{ "happy" : false }
Example response
-
204:
No Content
Get single property on a relationship
Example request
-
GET
http://localhost:7474/db/data/relationship/53/properties/cost
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
"high"
Set single property on a relationship
Example request
-
PUT
http://localhost:7474/db/data/relationship/51/properties/cost
-
Accept:
application/json; charset=UTF-8
-
Content-Type:
application/json
"deadly"
Example response
-
204:
No Content
Get all relationships
Example request
-
GET
http://localhost:7474/db/data/node/233/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/233", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/134", "property" : "http://localhost:7474/db/data/relationship/134/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/134/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/234" }, { "start" : "http://localhost:7474/db/data/node/235", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/135", "property" : "http://localhost:7474/db/data/relationship/135/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/135/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/233" }, { "start" : "http://localhost:7474/db/data/node/233", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/136", "property" : "http://localhost:7474/db/data/relationship/136/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/136/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/236" } ]
Get incoming relationships
Example request
-
GET
http://localhost:7474/db/data/node/252/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/254", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/146", "property" : "http://localhost:7474/db/data/relationship/146/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/146/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/252" } ]
Get outgoing relationships
Example request
-
GET
http://localhost:7474/db/data/node/277/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/277", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/160", "property" : "http://localhost:7474/db/data/relationship/160/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/160/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/278" }, { "start" : "http://localhost:7474/db/data/node/277", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/162", "property" : "http://localhost:7474/db/data/relationship/162/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/162/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/280" } ]
Get typed relationships
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/208/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/208", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/119", "property" : "http://localhost:7474/db/data/relationship/119/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/119/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/209" }, { "start" : "http://localhost:7474/db/data/node/210", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/120", "property" : "http://localhost:7474/db/data/relationship/120/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/120/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/208" }, { "start" : "http://localhost:7474/db/data/node/208", "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" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/211" } ]
Get relationships on a node without relationships
Example request
-
GET
http://localhost:7474/db/data/node/266/relationships/all
-
Accept:
application/json; charset=UTF-8
Example response
-
200:
OK
-
Content-Type:
application/json; charset=UTF-8
[ ]