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/18
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/47", "property" : "http://localhost:7474/db/data/relationship/18/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/18", "properties" : "http://localhost:7474/db/data/relationship/18/properties", "type" : "know", "end" : "http://localhost:7474/db/data/node/46", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/87/relationships
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/86", "type" : "LOVES" }
Example response
201:
Created
Content-Type:
application/json
Location:
http://localhost:7474/db/data/relationship/95
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/87", "property" : "http://localhost:7474/db/data/relationship/95/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/95", "properties" : "http://localhost:7474/db/data/relationship/95/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/86", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/85/relationships
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/84", "type" : "LOVES", "data" : { "foo" : "bar" } }
Example response
201:
Created
Content-Type:
application/json
Location:
http://localhost:7474/db/data/relationship/93
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/85", "property" : "http://localhost:7474/db/data/relationship/93/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/93", "properties" : "http://localhost:7474/db/data/relationship/93/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/84", "data" : { "foo" : "bar" } }
Example request
DELETE
http://localhost:7474/db/data/relationship/24
Accept:
application/json
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/28/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/27/properties
Accept:
application/json
Content-Type:
application/json
{ "happy" : false }
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/25/properties/cost
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
"high"
Example request
PUT
http://localhost:7474/db/data/relationship/26/properties/cost
Accept:
application/json
Content-Type:
application/json
"deadly"
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/node/78/relationships/all
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/78", "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/79" }, { "start" : "http://localhost:7474/db/data/node/80", "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" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/78" }, { "start" : "http://localhost:7474/db/data/node/78", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/37", "property" : "http://localhost:7474/db/data/relationship/37/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/37/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/81" } ]
Example request
GET
http://localhost:7474/db/data/node/88/relationships/in
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/90", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/42", "property" : "http://localhost:7474/db/data/relationship/42/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/42/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/88" } ]
Example request
GET
http://localhost:7474/db/data/node/93/relationships/out
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/93", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/44", "property" : "http://localhost:7474/db/data/relationship/44/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/44/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/94" }, { "start" : "http://localhost:7474/db/data/node/93", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/46", "property" : "http://localhost:7474/db/data/relationship/46/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/46/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/96" } ]
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/98/relationships/all/LIKES&HATES
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/98", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/47", "property" : "http://localhost:7474/db/data/relationship/47/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/47/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/99" }, { "start" : "http://localhost:7474/db/data/node/100", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/48", "property" : "http://localhost:7474/db/data/relationship/48/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/48/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/98" }, { "start" : "http://localhost:7474/db/data/node/98", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/49", "property" : "http://localhost:7474/db/data/relationship/49/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/49/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/101" } ]
Copyright © 2012 Neo Technology