19.3. Relationships

19.3.1. Get Relationship by ID
19.3.2. Create relationship
19.3.3. Create a relationship with properties
19.3.4. Delete relationship
19.3.5. Get all properties on a relationship
19.3.6. Set all properties on a relationship
19.3.7. Get single property on a relationship
19.3.8. Set single property on a relationship
19.3.9. Get all relationships
19.3.10. Get incoming relationships
19.3.11. Get outgoing relationships
19.3.12. Get typed relationships
19.3.13. Get relationships on a node without relationships

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.

19.3.1. Get Relationship by ID

Figure 19.8. Final Graph


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/24",
  "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/23"
}

19.3.2. Create relationship

Upon successful creation of a relationship, the new relationship is returned.

Figure 19.9. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/96/relationships
  • Accept: application/json
  • Content-Type: application/json
{"to" : "http://localhost:7474/db/data/node/95", "type" : "LOVES"}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/relationship/32
{
  "start" : "http://localhost:7474/db/data/node/96",
  "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" : "LOVES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/95"
}

19.3.3. Create a relationship with properties

Upon successful creation of a relationship, the new relationship is returned.

Figure 19.10. Starting Graph


Figure 19.11. Final Graph


Example request

  • POST http://localhost:7474/db/data/node/94/relationships
  • Accept: application/json
  • Content-Type: application/json
{"to" : "http://localhost:7474/db/data/node/93", "type" : "LOVES", "data" : {"foo" : "bar"}}

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/relationship/30
{
  "start" : "http://localhost:7474/db/data/node/94",
  "data" : {
    "foo" : "bar"
  },
  "self" : "http://localhost:7474/db/data/relationship/30",
  "property" : "http://localhost:7474/db/data/relationship/30/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/30/properties",
  "type" : "LOVES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/93"
}

19.3.4. Delete relationship

Figure 19.12. Starting Graph


Figure 19.13. Final Graph


Example request

  • DELETE http://localhost:7474/db/data/relationship/11
  • Accept: application/json

Example response

  • 204: No Content

19.3.5. Get all properties on a relationship

Figure 19.14. Final Graph


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"
}

19.3.6. Set all properties on a relationship

Figure 19.15. Starting Graph


Figure 19.16. Final Graph


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

19.3.7. Get single property on a relationship

Figure 19.17. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/12/properties/cost
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
"high"

19.3.8. Set single property on a relationship

Figure 19.18. Starting Graph


Figure 19.19. Final Graph


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

19.3.9. Get all relationships

Figure 19.20. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/139/relationships/all
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/139",
  "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/140"
}, {
  "start" : "http://localhost:7474/db/data/node/141",
  "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/139"
}, {
  "start" : "http://localhost:7474/db/data/node/139",
  "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/142"
} ]

19.3.10. Get incoming relationships

Figure 19.21. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/144/relationships/in
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/146",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/52",
  "property" : "http://localhost:7474/db/data/relationship/52/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/52/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/144"
} ]

19.3.11. Get outgoing relationships

Figure 19.22. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/149/relationships/out
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/149",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/54",
  "property" : "http://localhost:7474/db/data/relationship/54/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/54/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/150"
}, {
  "start" : "http://localhost:7474/db/data/node/149",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/56",
  "property" : "http://localhost:7474/db/data/relationship/56/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/56/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/152"
} ]

19.3.12. Get typed relationships

<p/> Note that the "&" needs to be escaped for example when using cURL from the terminal.

Figure 19.23. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/154/relationships/all/LIKES&HATES
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/154",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/57",
  "property" : "http://localhost:7474/db/data/relationship/57/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/57/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/155"
}, {
  "start" : "http://localhost:7474/db/data/node/156",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/58",
  "property" : "http://localhost:7474/db/data/relationship/58/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/58/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/154"
}, {
  "start" : "http://localhost:7474/db/data/node/154",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/59",
  "property" : "http://localhost:7474/db/data/relationship/59/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/59/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/157"
} ]

19.3.13. Get relationships on a node without relationships

Figure 19.24. Final Graph


Example request

  • GET http://localhost:7474/db/data/node/173/relationships/all
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
[ ]