- 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
-
GEThttp://localhost:7474/db/data/relationship/29 -
Accept:application/json; charset=UTF-8
Example response
-
200:OK -
Content-Type:application/json; charset=UTF-8
{
"extensions" : { },
"metadata" : {
"id" : 29,
"type" : "know"
},
"start" : "http://localhost:7474/db/data/node/108",
"property" : "http://localhost:7474/db/data/relationship/29/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/29",
"end" : "http://localhost:7474/db/data/node/109",
"type" : "know",
"properties" : "http://localhost:7474/db/data/relationship/29/properties",
"data" : { }
}
Create relationship
Upon successful creation of a relationship, the new relationship is returned.
Example request
-
POSThttp://localhost:7474/db/data/node/72/relationships -
Accept:application/json; charset=UTF-8 -
Content-Type:application/json
{
"to" : "http://localhost:7474/db/data/node/73",
"type" : "LOVES"
}
Example response
-
201:Created -
Content-Type:application/json; charset=UTF-8 -
Location:http://localhost:7474/db/data/relationship/27
{
"extensions" : { },
"metadata" : {
"id" : 27,
"type" : "LOVES"
},
"property" : "http://localhost:7474/db/data/relationship/27/properties/{key}",
"start" : "http://localhost:7474/db/data/node/72",
"self" : "http://localhost:7474/db/data/relationship/27",
"end" : "http://localhost:7474/db/data/node/73",
"type" : "LOVES",
"properties" : "http://localhost:7474/db/data/relationship/27/properties",
"data" : { }
}
Create a relationship with properties
Upon successful creation of a relationship, the new relationship is returned.
Example request
-
POSThttp://localhost:7474/db/data/node/82/relationships -
Accept:application/json; charset=UTF-8 -
Content-Type:application/json
{
"to" : "http://localhost:7474/db/data/node/83",
"type" : "LOVES",
"data" : {
"foo" : "bar"
}
}
Example response
-
201:Created -
Content-Type:application/json; charset=UTF-8 -
Location:http://localhost:7474/db/data/relationship/34
{
"extensions" : { },
"metadata" : {
"id" : 34,
"type" : "LOVES"
},
"property" : "http://localhost:7474/db/data/relationship/34/properties/{key}",
"start" : "http://localhost:7474/db/data/node/82",
"self" : "http://localhost:7474/db/data/relationship/34",
"end" : "http://localhost:7474/db/data/node/83",
"type" : "LOVES",
"properties" : "http://localhost:7474/db/data/relationship/34/properties",
"data" : {
"foo" : "bar"
}
}
Delete relationship
Example request
-
DELETEhttp://localhost:7474/db/data/relationship/22 -
Accept:application/json; charset=UTF-8
Example response
-
204:No Content
Get all properties on a relationship
Example request
-
GEThttp://localhost:7474/db/data/relationship/25/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
-
PUThttp://localhost:7474/db/data/relationship/30/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
-
GEThttp://localhost:7474/db/data/relationship/26/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
-
PUThttp://localhost:7474/db/data/relationship/24/properties/cost -
Accept:application/json; charset=UTF-8 -
Content-Type:application/json
"deadly"
Example response
-
204:No Content
Get all relationships
Example request
-
GEThttp://localhost:7474/db/data/node/285/relationships/all -
Accept:application/json; charset=UTF-8
Example response
-
200:OK -
Content-Type:application/json; charset=UTF-8
[ {
"extensions" : { },
"metadata" : {
"id" : 193,
"type" : "HATES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/285",
"property" : "http://localhost:7474/db/data/relationship/193/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/193",
"end" : "http://localhost:7474/db/data/node/288",
"type" : "HATES",
"properties" : "http://localhost:7474/db/data/relationship/193/properties"
}, {
"extensions" : { },
"metadata" : {
"id" : 192,
"type" : "LIKES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/287",
"property" : "http://localhost:7474/db/data/relationship/192/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/192",
"end" : "http://localhost:7474/db/data/node/285",
"type" : "LIKES",
"properties" : "http://localhost:7474/db/data/relationship/192/properties"
}, {
"extensions" : { },
"metadata" : {
"id" : 191,
"type" : "LIKES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/285",
"property" : "http://localhost:7474/db/data/relationship/191/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/191",
"end" : "http://localhost:7474/db/data/node/286",
"type" : "LIKES",
"properties" : "http://localhost:7474/db/data/relationship/191/properties"
} ]
Get incoming relationships
Example request
-
GEThttp://localhost:7474/db/data/node/304/relationships/in -
Accept:application/json; charset=UTF-8
Example response
-
200:OK -
Content-Type:application/json; charset=UTF-8
[ {
"extensions" : { },
"metadata" : {
"id" : 203,
"type" : "LIKES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/306",
"property" : "http://localhost:7474/db/data/relationship/203/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/203",
"end" : "http://localhost:7474/db/data/node/304",
"type" : "LIKES",
"properties" : "http://localhost:7474/db/data/relationship/203/properties"
} ]
Get outgoing relationships
Example request
-
GEThttp://localhost:7474/db/data/node/329/relationships/out -
Accept:application/json; charset=UTF-8
Example response
-
200:OK -
Content-Type:application/json; charset=UTF-8
[ {
"extensions" : { },
"metadata" : {
"id" : 219,
"type" : "HATES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/329",
"property" : "http://localhost:7474/db/data/relationship/219/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/219",
"end" : "http://localhost:7474/db/data/node/332",
"type" : "HATES",
"properties" : "http://localhost:7474/db/data/relationship/219/properties"
}, {
"extensions" : { },
"metadata" : {
"id" : 217,
"type" : "LIKES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/329",
"property" : "http://localhost:7474/db/data/relationship/217/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/217",
"end" : "http://localhost:7474/db/data/node/330",
"type" : "LIKES",
"properties" : "http://localhost:7474/db/data/relationship/217/properties"
} ]
Get typed relationships
Note that the "&" needs to be encoded like "%26" for example when
using cURL from the terminal.
Example request
-
GEThttp://localhost:7474/db/data/node/260/relationships/all/LIKES&HATES -
Accept:application/json; charset=UTF-8
Example response
-
200:OK -
Content-Type:application/json; charset=UTF-8
[ {
"extensions" : { },
"metadata" : {
"id" : 178,
"type" : "HATES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/260",
"property" : "http://localhost:7474/db/data/relationship/178/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/178",
"end" : "http://localhost:7474/db/data/node/263",
"type" : "HATES",
"properties" : "http://localhost:7474/db/data/relationship/178/properties"
}, {
"extensions" : { },
"metadata" : {
"id" : 177,
"type" : "LIKES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/262",
"property" : "http://localhost:7474/db/data/relationship/177/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/177",
"end" : "http://localhost:7474/db/data/node/260",
"type" : "LIKES",
"properties" : "http://localhost:7474/db/data/relationship/177/properties"
}, {
"extensions" : { },
"metadata" : {
"id" : 176,
"type" : "LIKES"
},
"data" : { },
"start" : "http://localhost:7474/db/data/node/260",
"property" : "http://localhost:7474/db/data/relationship/176/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/176",
"end" : "http://localhost:7474/db/data/node/261",
"type" : "LIKES",
"properties" : "http://localhost:7474/db/data/relationship/176/properties"
} ]
Get relationships on a node without relationships
Example request
-
GEThttp://localhost:7474/db/data/node/318/relationships/all -
Accept:application/json; charset=UTF-8
Example response
-
200:OK -
Content-Type:application/json; charset=UTF-8
[ ]