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/182
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/295", "property" : "http://localhost:7474/db/data/relationship/182/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/182", "properties" : "http://localhost:7474/db/data/relationship/182/properties", "type" : "know", "end" : "http://localhost:7474/db/data/node/294", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/333/relationships
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/332", "type" : "LOVES" }
Example response
201:
Created
Content-Type:
application/json
Location:
http://localhost:7474/db/data/relationship/200
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/333", "property" : "http://localhost:7474/db/data/relationship/200/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/200", "properties" : "http://localhost:7474/db/data/relationship/200/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/332", "data" : { } }
Upon successful creation of a relationship, the new relationship is returned.
Example request
POST
http://localhost:7474/db/data/node/343/relationships
Accept:
application/json
Content-Type:
application/json
{ "to" : "http://localhost:7474/db/data/node/342", "type" : "LOVES", "data" : { "foo" : "bar" } }
Example response
201:
Created
Content-Type:
application/json
Location:
http://localhost:7474/db/data/relationship/207
{ "extensions" : { }, "start" : "http://localhost:7474/db/data/node/343", "property" : "http://localhost:7474/db/data/relationship/207/properties/{key}", "self" : "http://localhost:7474/db/data/relationship/207", "properties" : "http://localhost:7474/db/data/relationship/207/properties", "type" : "LOVES", "end" : "http://localhost:7474/db/data/node/342", "data" : { "foo" : "bar" } }
Example request
DELETE
http://localhost:7474/db/data/relationship/175
Accept:
application/json
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/178/properties
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
{ "cost" : "high", "since" : "1day" }
Example request
PUT
http://localhost:7474/db/data/relationship/183/properties
Accept:
application/json
Content-Type:
application/json
{ "happy" : false }
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/relationship/179/properties/cost
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
"high"
Example request
PUT
http://localhost:7474/db/data/relationship/177/properties/cost
Accept:
application/json
Content-Type:
application/json
"deadly"
Example response
204:
No Content
Example request
GET
http://localhost:7474/db/data/node/389/relationships/all
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/389", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/235", "property" : "http://localhost:7474/db/data/relationship/235/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/235/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/390" }, { "start" : "http://localhost:7474/db/data/node/391", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/236", "property" : "http://localhost:7474/db/data/relationship/236/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/236/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/389" }, { "start" : "http://localhost:7474/db/data/node/389", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/237", "property" : "http://localhost:7474/db/data/relationship/237/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/237/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/392" } ]
Example request
GET
http://localhost:7474/db/data/node/408/relationships/in
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/410", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/247", "property" : "http://localhost:7474/db/data/relationship/247/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/247/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/408" } ]
Example request
GET
http://localhost:7474/db/data/node/433/relationships/out
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/433", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/261", "property" : "http://localhost:7474/db/data/relationship/261/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/261/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/434" }, { "start" : "http://localhost:7474/db/data/node/433", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/263", "property" : "http://localhost:7474/db/data/relationship/263/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/263/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/436" } ]
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/364/relationships/all/LIKES&HATES
Accept:
application/json
Example response
200:
OK
Content-Type:
application/json
[ { "start" : "http://localhost:7474/db/data/node/364", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/220", "property" : "http://localhost:7474/db/data/relationship/220/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/220/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/365" }, { "start" : "http://localhost:7474/db/data/node/366", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/221", "property" : "http://localhost:7474/db/data/relationship/221/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/221/properties", "type" : "LIKES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/364" }, { "start" : "http://localhost:7474/db/data/node/364", "data" : { }, "self" : "http://localhost:7474/db/data/relationship/222", "property" : "http://localhost:7474/db/data/relationship/222/properties/{key}", "properties" : "http://localhost:7474/db/data/relationship/222/properties", "type" : "HATES", "extensions" : { }, "end" : "http://localhost:7474/db/data/node/367" } ]
Copyright © 2013 Neo Technology