Prev |  | Next

## 20.8. 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.

### 20.8.1. Get Relationship by ID

Figure 20.19. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/relationship/30`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    {
      "extensions" : {
      },
      "start" : "http://localhost:7474/db/data/node/138",
      "property" : "http://localhost:7474/db/data/relationship/30/properties/{key}",
      "self" : "http://localhost:7474/db/data/relationship/30",
      "properties" : "http://localhost:7474/db/data/relationship/30/properties",
      "type" : "know",
      "end" : "http://localhost:7474/db/data/node/137",
      "data" : {
      }
    }

### 20.8.2. Create relationship

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

Figure 20.20. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/node/1/relationships`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

    {
      "to" : "http://localhost:7474/db/data/node/0",
      "type" : "LOVES"
    }

Example response

- `201:` `Created`
- `Content-Type:` `application/json; charset=UTF-8`
- `Location:` `http://localhost:7474/db/data/relationship/1`

    {
      "extensions" : {
      },
      "start" : "http://localhost:7474/db/data/node/1",
      "property" : "http://localhost:7474/db/data/relationship/1/properties/{key}",
      "self" : "http://localhost:7474/db/data/relationship/1",
      "properties" : "http://localhost:7474/db/data/relationship/1/properties",
      "type" : "LOVES",
      "end" : "http://localhost:7474/db/data/node/0",
      "data" : {
      }
    }

### 20.8.3. Create a relationship with properties

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

Figure 20.21. Starting Graph

Figure 20.22. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/node/11/relationships`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

    {
      "to" : "http://localhost:7474/db/data/node/10",
      "type" : "LOVES",
      "data" : {
        "foo" : "bar"
      }
    }

Example response

- `201:` `Created`
- `Content-Type:` `application/json; charset=UTF-8`
- `Location:` `http://localhost:7474/db/data/relationship/8`

    {
      "extensions" : {
      },
      "start" : "http://localhost:7474/db/data/node/11",
      "property" : "http://localhost:7474/db/data/relationship/8/properties/{key}",
      "self" : "http://localhost:7474/db/data/relationship/8",
      "properties" : "http://localhost:7474/db/data/relationship/8/properties",
      "type" : "LOVES",
      "end" : "http://localhost:7474/db/data/node/10",
      "data" : {
        "foo" : "bar"
      }
    }

### 20.8.4. Delete relationship

Figure 20.23. Starting Graph

Figure 20.24. Final Graph

Example request

- `DELETE` `http://localhost:7474/db/data/relationship/23`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `204:` `No Content`

### 20.8.5. Get all properties on a relationship

Figure 20.25. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/relationship/26/properties`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    {
      "cost" : "high",
      "since" : "1day"
    }

### 20.8.6. Set all properties on a relationship

Figure 20.26. Starting Graph

Figure 20.27. Final Graph

Example request

- `PUT` `http://localhost:7474/db/data/relationship/31/properties`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

    {
      "happy" : false
    }

Example response

- `204:` `No Content`

### 20.8.7. Get single property on a relationship

Figure 20.28. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/relationship/27/properties/cost`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    "high"

### 20.8.8. Set single property on a relationship

Figure 20.29. Starting Graph

Figure 20.30. Final Graph

Example request

- `PUT` `http://localhost:7474/db/data/relationship/25/properties/cost`
- `Accept:` `application/json; charset=UTF-8`
- `Content-Type:` `application/json`

    "deadly"

Example response

- `204:` `No Content`

### 20.8.9. Get all relationships

Figure 20.31. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/node/298/relationships/all`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    [ {
      "start" : "http://localhost:7474/db/data/node/298",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/204",
      "property" : "http://localhost:7474/db/data/relationship/204/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/204/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/299"
    }, {
      "start" : "http://localhost:7474/db/data/node/300",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/205",
      "property" : "http://localhost:7474/db/data/relationship/205/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/205/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/298"
    }, {
      "start" : "http://localhost:7474/db/data/node/298",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/206",
      "property" : "http://localhost:7474/db/data/relationship/206/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/206/properties",
      "type" : "HATES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/301"
    } ]

### 20.8.10. Get incoming relationships

Figure 20.32. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/node/317/relationships/in`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    [ {
      "start" : "http://localhost:7474/db/data/node/319",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/216",
      "property" : "http://localhost:7474/db/data/relationship/216/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/216/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/317"
    } ]

### 20.8.11. Get outgoing relationships

Figure 20.33. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/node/342/relationships/out`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    [ {
      "start" : "http://localhost:7474/db/data/node/342",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/230",
      "property" : "http://localhost:7474/db/data/relationship/230/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/230/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/343"
    }, {
      "start" : "http://localhost:7474/db/data/node/342",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/232",
      "property" : "http://localhost:7474/db/data/relationship/232/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/232/properties",
      "type" : "HATES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/345"
    } ]

### 20.8.12. Get typed relationships

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

Figure 20.34. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/node/273/relationships/all/LIKES&HATES`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    [ {
      "start" : "http://localhost:7474/db/data/node/273",
      "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" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/274"
    }, {
      "start" : "http://localhost:7474/db/data/node/275",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/190",
      "property" : "http://localhost:7474/db/data/relationship/190/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/190/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/273"
    }, {
      "start" : "http://localhost:7474/db/data/node/273",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/191",
      "property" : "http://localhost:7474/db/data/relationship/191/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/191/properties",
      "type" : "HATES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/276"
    } ]

### 20.8.13. Get relationships on a node without relationships

Figure 20.35. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/node/331/relationships/all`
- `Accept:` `application/json; charset=UTF-8`

Example response

- `200:` `OK`
- `Content-Type:` `application/json; charset=UTF-8`

    [ ]

Copyright © 2014 Neo Technology

Prev | Up | Next
| Home |