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/1
Accept: application/json
Example response
200: OK
Content-Type: application/json
{
"start" : "http://localhost:7474/db/data/node/4",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/1",
"property" : "http://localhost:7474/db/data/relationship/1/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/1/properties",
"type" : "know",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/3"
}Documentation not available
Example request
POST http://localhost:7474/db/data/node/4/relationships
Accept: application/json
Content-Type: application/json
{"to" : "http://localhost:7474/db/data/node/3", "type" : "LOVES", "data" : {"foo" : "bar"}}Example response
201: Created
Content-Type: application/json
Location: http://localhost:7474/db/data/relationship/3
{
"start" : "http://localhost:7474/db/data/node/4",
"data" : {
"foo" : "bar"
},
"self" : "http://localhost:7474/db/data/relationship/3",
"property" : "http://localhost:7474/db/data/relationship/3/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/3/properties",
"type" : "LOVES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/3"
}Example request
POST http://localhost:7474/db/data/node/2/relationships
Accept: application/json
Content-Type: application/json
{"to" : "http://localhost:7474/db/data/node/1", "type" : "LOVES", "data" : {"foo" : "bar"}}Example response
201: Created
Content-Type: application/json
Location: http://localhost:7474/db/data/relationship/1
{
"start" : "http://localhost:7474/db/data/node/2",
"data" : {
"foo" : "bar"
},
"self" : "http://localhost:7474/db/data/relationship/1",
"property" : "http://localhost:7474/db/data/relationship/1/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/1/properties",
"type" : "LOVES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/1"
}Example request
DELETE http://localhost:7474/db/data/relationship/6
Accept: application/json
Example response
204: No Content
Example request
GET http://localhost:7474/db/data/node/6/relationships/all
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/6",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/3",
"property" : "http://localhost:7474/db/data/relationship/3/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/3/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/7"
}, {
"start" : "http://localhost:7474/db/data/node/8",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/4",
"property" : "http://localhost:7474/db/data/relationship/4/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/4/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/6"
}, {
"start" : "http://localhost:7474/db/data/node/6",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/5",
"property" : "http://localhost:7474/db/data/relationship/5/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/5/properties",
"type" : "HATES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/9"
} ]Example request
GET http://localhost:7474/db/data/node/11/relationships/in
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/13",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/7",
"property" : "http://localhost:7474/db/data/relationship/7/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/7/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/11"
} ]Example request
GET http://localhost:7474/db/data/node/16/relationships/out
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/16",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/9",
"property" : "http://localhost:7474/db/data/relationship/9/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/9/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/17"
}, {
"start" : "http://localhost:7474/db/data/node/16",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/11",
"property" : "http://localhost:7474/db/data/relationship/11/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/11/properties",
"type" : "HATES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/19"
} ]Note that the "&" needs to be escaped for example when using
cURL from the terminal.
Example request
GET http://localhost:7474/db/data/node/21/relationships/all/LIKES&HATES
Accept: application/json
Example response
200: OK
Content-Type: application/json
[ {
"start" : "http://localhost:7474/db/data/node/21",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/12",
"property" : "http://localhost:7474/db/data/relationship/12/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/12/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/22"
}, {
"start" : "http://localhost:7474/db/data/node/23",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/13",
"property" : "http://localhost:7474/db/data/relationship/13/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/13/properties",
"type" : "LIKES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/21"
}, {
"start" : "http://localhost:7474/db/data/node/21",
"data" : {
},
"self" : "http://localhost:7474/db/data/relationship/14",
"property" : "http://localhost:7474/db/data/relationship/14/properties/{key}",
"properties" : "http://localhost:7474/db/data/relationship/14/properties",
"type" : "HATES",
"extensions" : {
},
"end" : "http://localhost:7474/db/data/node/24"
} ]Copyright © 2011 Neo Technology