Prev |  | Next

## 18.3. 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.3.1. Get Relationship by ID

Figure 18.2. Final Graph

Example request

- `GET` `http://localhost:7474/db/data/relationship/1`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

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

### 18.3.2. Create relationship

Documentation not available

Figure 18.3. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/node/4/relationships`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

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

Example response

- `201:` `Created`
- `Content-Type:` `application/json`
- `Location:` `http://localhost:7474/db/data/relationship/3`

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

### 18.3.3. Create a relationship with properties

Figure 18.4. Starting Graph

Figure 18.5. Final Graph

Example request

- `POST` `http://localhost:7474/db/data/node/2/relationships`
- `Accept:` `application/json`
- `Content-Type:` `application/json`

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

Example response

- `201:` `Created`
- `Content-Type:` `application/json`
- `Location:` `http://localhost:7474/db/data/relationship/1`

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

### 18.3.4. Delete relationship

Figure 18.6. Starting Graph

Figure 18.7. Final Graph

Example request

- `DELETE` `http://localhost:7474/db/data/relationship/6`
- `Accept:` `application/json`

Example response

- `204:` `No Content`

### 18.3.5. Get all relationships

Example request

- `GET` `http://localhost:7474/db/data/node/6/relationships/all`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    [ {
      "start" : "http://localhost:7474/db/data/node/6",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/3",
      "property" : "http://localhost:7474/db/data/relationship/3/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/3/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/7"
    }, {
      "start" : "http://localhost:7474/db/data/node/8",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/4",
      "property" : "http://localhost:7474/db/data/relationship/4/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/4/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/6"
    }, {
      "start" : "http://localhost:7474/db/data/node/6",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/5",
      "property" : "http://localhost:7474/db/data/relationship/5/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/5/properties",
      "type" : "HATES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/9"
    } ]

### 18.3.6. Get incoming relationships

Example request

- `GET` `http://localhost:7474/db/data/node/11/relationships/in`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

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

### 18.3.7. Get outgoing relationships

Example request

- `GET` `http://localhost:7474/db/data/node/16/relationships/out`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    [ {
      "start" : "http://localhost:7474/db/data/node/16",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/9",
      "property" : "http://localhost:7474/db/data/relationship/9/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/9/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/17"
    }, {
      "start" : "http://localhost:7474/db/data/node/16",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/11",
      "property" : "http://localhost:7474/db/data/relationship/11/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/11/properties",
      "type" : "HATES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/19"
    } ]

### 18.3.8. Get typed relationships

Note that the "`&`" needs to be escaped for example when using cURL from the terminal.

Example request

- `GET` `http://localhost:7474/db/data/node/21/relationships/all/LIKES&HATES`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    [ {
      "start" : "http://localhost:7474/db/data/node/21",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/12",
      "property" : "http://localhost:7474/db/data/relationship/12/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/12/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/22"
    }, {
      "start" : "http://localhost:7474/db/data/node/23",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/13",
      "property" : "http://localhost:7474/db/data/relationship/13/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/13/properties",
      "type" : "LIKES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/21"
    }, {
      "start" : "http://localhost:7474/db/data/node/21",
      "data" : {
      },
      "self" : "http://localhost:7474/db/data/relationship/14",
      "property" : "http://localhost:7474/db/data/relationship/14/properties/{key}",
      "properties" : "http://localhost:7474/db/data/relationship/14/properties",
      "type" : "HATES",
      "extensions" : {
      },
      "end" : "http://localhost:7474/db/data/node/24"
    } ]

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

Example request

- `GET` `http://localhost:7474/db/data/node/40/relationships/all`
- `Accept:` `application/json`

Example response

- `200:` `OK`
- `Content-Type:` `application/json`

    [ ]

Copyright © 2011 Neo Technology

Prev | Up | Next
| Home |