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/5
Accept: application/json
Example response
200: OK
Content-Type: application/json
{
"extensions" : {
},
"start" : "http://localhost:7474/db/data/node/7",
"property" : "http://localhost:7474/db/data/relationship/5/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/5",
"properties" : "http://localhost:7474/db/data/relationship/5/properties",
"type" : "know",
"end" : "http://localhost:7474/db/data/node/6",
"data" : {
}
}Upon successful creation of a relationship, the new relationship is returned.
Example request
POST http://localhost:7474/db/data/node/25/relationships
Accept: application/json
Content-Type: application/json
{
"to" : "http://localhost:7474/db/data/node/24",
"type" : "LOVES"
}Example response
201: Created
Content-Type: application/json
Location: http://localhost:7474/db/data/relationship/31
{
"extensions" : {
},
"start" : "http://localhost:7474/db/data/node/25",
"property" : "http://localhost:7474/db/data/relationship/31/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/31",
"properties" : "http://localhost:7474/db/data/relationship/31/properties",
"type" : "LOVES",
"end" : "http://localhost:7474/db/data/node/24",
"data" : {
}
}Upon successful creation of a relationship, the new relationship is returned.
Example request
POST http://localhost:7474/db/data/node/23/relationships
Accept: application/json
Content-Type: application/json
{
"to" : "http://localhost:7474/db/data/node/22",
"type" : "LOVES",
"data" : {
"foo" : "bar"
}
}Example response
201: Created
Content-Type: application/json
Location: http://localhost:7474/db/data/relationship/29
{
"extensions" : {
},
"start" : "http://localhost:7474/db/data/node/23",
"property" : "http://localhost:7474/db/data/relationship/29/properties/{key}",
"self" : "http://localhost:7474/db/data/relationship/29",
"properties" : "http://localhost:7474/db/data/relationship/29/properties",
"type" : "LOVES",
"end" : "http://localhost:7474/db/data/node/22",
"data" : {
"foo" : "bar"
}
}Example request
DELETE http://localhost:7474/db/data/relationship/11
Accept: application/json
Example response
204: No Content
Example request
GET http://localhost:7474/db/data/relationship/15/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/14/properties
Accept: application/json
Content-Type: application/json
{
"happy" : false
}Example response
204: No Content
Example request
GET http://localhost:7474/db/data/relationship/12/properties/cost
Accept: application/json
Example response
200: OK
Content-Type: application/json
"high"
Example request
PUT http://localhost:7474/db/data/relationship/13/properties/cost
Accept: application/json
Content-Type: application/json
"deadly"
Example response
204: No Content
Example request
GET http://localhost:7474/db/data/node/38/relationships/all
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/38",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/22",
"property" : "http://localhost:7474/db/data/relationship/22/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/22/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/39"
}, {
"start" : "http://localhost:7474/db/data/node/40",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/23",
"property" : "http://localhost:7474/db/data/relationship/23/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/23/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/38"
}, {
"start" : "http://localhost:7474/db/data/node/38",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/24",
"property" : "http://localhost:7474/db/data/relationship/24/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/24/properties",
"type" : "HATES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/41"
} ]Example request
GET http://localhost:7474/db/data/node/48/relationships/in
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/50",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/29",
"property" : "http://localhost:7474/db/data/relationship/29/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/29/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/48"
} ]Example request
GET http://localhost:7474/db/data/node/53/relationships/out
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/53",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/31",
"property" : "http://localhost:7474/db/data/relationship/31/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/31/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/54"
}, {
"start" : "http://localhost:7474/db/data/node/53",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/33",
"property" : "http://localhost:7474/db/data/relationship/33/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/33/properties",
"type" : "HATES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/56"
} ]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/58/relationships/all/LIKES&HATES
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/58",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/34",
"property" : "http://localhost:7474/db/data/relationship/34/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/34/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/59"
}, {
"start" : "http://localhost:7474/db/data/node/60",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/35",
"property" : "http://localhost:7474/db/data/relationship/35/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/35/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/58"
}, {
"start" : "http://localhost:7474/db/data/node/58",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/36",
"property" : "http://localhost:7474/db/data/relationship/36/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/36/properties",
"type" : "HATES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/61"
} ]Copyright © 2013 Neo Technology