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/15
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
{ "start" : "http://localhost:7474/db/data/node/42", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/15", "property" : "http://localhost:7474/db/data/relationship/15/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/15/properties", "type" : "know", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/41" }
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
{ "start" : "http://localhost:7474/db/data/node/87", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/95", "property" : "http://localhost:7474/db/data/relationship/95/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/95/properties", "type" : "LOVES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/86" }
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
{ "start" : "http://localhost:7474/db/data/node/85", "data" : { "foo" : "bar" }, "self" : "http://localhost:7474/db/data/relationship/93", "property" : "http://localhost:7474/db/data/relationship/93/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/93/properties", "type" : "LOVES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/84" }
Example request
DELETE
http://localhost:7474/db/data/relationship/20
Accept:
application/json
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/24/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/23/properties
Accept:
application/json
Content-Type:
application/json
{ "happy" : false }
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/21/properties/cost
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
"high"
Example request
PUT
http://localhost:7474/db/data/relationship/22/properties/cost
Accept:
application/json
Content-Type:
application/json
"deadly"
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/node/71/relationships/all
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/71", "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/72" }, { "start" : "http://localhost:7474/db/data/node/73", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/32", "property" : "http://localhost:7474/db/data/relationship/32/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/32/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/71" }, { "start" : "http://localhost:7474/db/data/node/71", "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/74" } ]
Example request
GET
http://localhost:7474/db/data/node/76/relationships/in
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/76" } ]
Example request
GET
http://localhost:7474/db/data/node/81/relationships/out
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/81", "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" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/82" }, { "start" : "http://localhost:7474/db/data/node/81", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/39", "property" : "http://localhost:7474/db/data/relationship/39/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/39/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/84" } ]
<p/>
Note that the "&
" needs to be escaped for example when using
cURL from the terminal.
Example request
GET
http://localhost:7474/db/data/node/86/relationships/all/LIKES&HATES
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/86", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/40", "property" : "http://localhost:7474/db/data/relationship/40/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/40/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/87" }, { "start" : "http://localhost:7474/db/data/node/88", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/41", "property" : "http://localhost:7474/db/data/relationship/41/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/41/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/86" }, { "start" : "http://localhost:7474/db/data/node/86", "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" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/89" } ]
Copyright © 2012 Neo Technology