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/6
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
{ "start" : "http://localhost:7474/db/data/node/22", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/6", "property" : "http://localhost:7474/db/data/relationship/6/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/6/properties", "type" : "know", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/21" }
Documentation not available
Example request
POST
http://localhost:7474/db/data/node/86/relationships
Accept:
application/json
Content-Type:
application/json
{"to" : "http://localhost:7474/db/data/node/85", "type" : "LOVES", "data" : {"foo" : "bar"}}
Example response
201:
Created
Content-Type:
application/json
Location:
http://localhost:7474/db/data/relationship/29
{ "start" : "http://localhost:7474/db/data/node/86", "data" : { "foo" : "bar" }, "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" : "LOVES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/85" }
Example request
POST
http://localhost:7474/db/data/node/84/relationships
Accept:
application/json
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
Location:
http://localhost:7474/db/data/relationship/27
{ "start" : "http://localhost:7474/db/data/node/84", "data" : { "foo" : "bar" }, "self" : "http://localhost:7474/db/data/relationship/27", "property" : "http://localhost:7474/db/data/relationship/27/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/27/properties", "type" : "LOVES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/83" }
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/113/relationships/all
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/113", "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" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/114" }, { "start" : "http://localhost:7474/db/data/node/115", "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/113" }, { "start" : "http://localhost:7474/db/data/node/113", "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" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/116" } ]
Example request
GET
http://localhost:7474/db/data/node/118/relationships/in
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/120", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/43", "property" : "http://localhost:7474/db/data/relationship/43/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/43/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/118" } ]
Example request
GET
http://localhost:7474/db/data/node/123/relationships/out
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/123", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/45", "property" : "http://localhost:7474/db/data/relationship/45/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/45/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/124" }, { "start" : "http://localhost:7474/db/data/node/123", "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" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/126" } ]
Note that the "&
" needs to be escaped for example when using
cURL from the terminal.
Example request
GET
http://localhost:7474/db/data/node/128/relationships/all/LIKES&HATES
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/128", "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/129" }, { "start" : "http://localhost:7474/db/data/node/130", "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" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/128" }, { "start" : "http://localhost:7474/db/data/node/128", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/50", "property" : "http://localhost:7474/db/data/relationship/50/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/50/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/131" } ]
Copyright © 2011 Neo Technology