18.5. Relationships

18.5.1. Get Relationship by ID
18.5.2. Create relationship
18.5.3. Create a relationship with properties
18.5.4. Delete relationship
18.5.5. Get all properties on a relationship
18.5.6. Set all properties on a relationship
18.5.7. Get single property on a relationship
18.5.8. Set single property on a relationship
18.5.9. Get all relationships
18.5.10. Get incoming relationships
18.5.11. Get outgoing relationships
18.5.12. Get typed relationships
18.5.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.

18.5.1. Get Relationship by ID

Figure 18.14. Final Graph


Example request

  • GET http://localhost:7474/db/data/relationship/150
  • Accept: application/json

Example response

  • 200: OK
  • Content-Type: application/json
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/249",
  "property" : "http://localhost:7474/db/data/relationship/150/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/150",
  "properties" : "http://localhost:7474/db/data/relationship/150/properties",
  "type" : "know",
  "end" : "http://localhost:7474/db/data/node/248",
  "data" : {
  }
}

18.5.2. Create relationship

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

Figure 18.15. Final Graph


Example request

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

Example response

  • 201: Created
  • Content-Type: application/json
  • Location: http://localhost:7474/db/data/relationship/170
{
  "extensions" : {
  },
  "start" : "http://localhost:7474/db/data/node/285",
  "property" : "http://localhost:7474/db/data/relationship/170/properties/{key}",
  "self" : "http://localhost:7474/db/data/relationship/170",
  "properties" : "http://localhost:7474/db/data/relationship/170/properties",
  "type" : "LOVES",
  "end" : "http://localhost:7474/db/data/node/284",
  "data" : {
  }
}

18.5.3. Create a relationship with properties

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

Figure 18.16. Starting Graph


Figure 18.17. Final Graph


Example request

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

Example response

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

18.5.4. Delete relationship

Figure 18.18. Starting Graph


Figure 18.19. Final Graph


Example request

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

Example response

  • 204: No Content

18.5.5. Get all properties on a relationship

Figure 18.20. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json
{
  "since" : "1day",
  "cost" : "high"
}

18.5.6. Set all properties on a relationship

Figure 18.21. Starting Graph


Figure 18.22. Final Graph


Example request

  • PUT http://localhost:7474/db/data/relationship/159/properties
  • Accept: application/json
  • Content-Type: application/json
{
  "happy" : false
}

Example response

  • 204: No Content

18.5.7. Get single property on a relationship

Figure 18.23. Final Graph


Example request

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

Example response

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

18.5.8. Set single property on a relationship

Figure 18.24. Starting Graph


Figure 18.25. Final Graph


Example request

  • PUT http://localhost:7474/db/data/relationship/158/properties/cost
  • Accept: application/json
  • Content-Type: application/json
"deadly"

Example response

  • 204: No Content

18.5.9. Get all relationships

Figure 18.26. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/311",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/187",
  "property" : "http://localhost:7474/db/data/relationship/187/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/187/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/312"
}, {
  "start" : "http://localhost:7474/db/data/node/313",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/188",
  "property" : "http://localhost:7474/db/data/relationship/188/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/188/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/311"
}, {
  "start" : "http://localhost:7474/db/data/node/311",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/189",
  "property" : "http://localhost:7474/db/data/relationship/189/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/189/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/314"
} ]

18.5.10. Get incoming relationships

Figure 18.27. Final Graph


Example request

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

Example response

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

18.5.11. Get outgoing relationships

Figure 18.28. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/326",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/196",
  "property" : "http://localhost:7474/db/data/relationship/196/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/196/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/327"
}, {
  "start" : "http://localhost:7474/db/data/node/326",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/198",
  "property" : "http://localhost:7474/db/data/relationship/198/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/198/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/329"
} ]

18.5.12. Get typed relationships

Note that the "&" needs to be encoded like "%26" for example when using cURL from the terminal.

Figure 18.29. Final Graph


Example request

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

Example response

  • 200: OK
  • Content-Type: application/json
[ {
  "start" : "http://localhost:7474/db/data/node/331",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/199",
  "property" : "http://localhost:7474/db/data/relationship/199/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/199/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/332"
}, {
  "start" : "http://localhost:7474/db/data/node/333",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/200",
  "property" : "http://localhost:7474/db/data/relationship/200/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/200/properties",
  "type" : "LIKES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/331"
}, {
  "start" : "http://localhost:7474/db/data/node/331",
  "data" : {
  },
  "self" : "http://localhost:7474/db/data/relationship/201",
  "property" : "http://localhost:7474/db/data/relationship/201/properties/{key}",
  "properties" : "http://localhost:7474/db/data/relationship/201/properties",
  "type" : "HATES",
  "extensions" : {
  },
  "end" : "http://localhost:7474/db/data/node/334"
} ]

18.5.13. Get relationships on a node without relationships

Figure 18.30. Final Graph


Example request

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

Example response

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