# HTTP Methods

This file covers deprecated v1 HTTP API. All the methods of v2 HTTP API is described in OpenAPI/Swagger [spec](https://github.com/cayleygraph/cayley/tree/87c9c341848b59924a054ebc2dd0f2bf8c57c6a9/docs/api/swagger.yml) and can be viewed by importing `https://raw.githubusercontent.com/cayleygraph/cayley/master/docs/api/swagger.yml` URL into [Swagger Editor](https://editor.swagger.io/) or [Swagger UI demo](http://petstore.swagger.io/).

## Gephi

Cayley supports streaming to Gephi via [GraphStream](https://cayley.gitbook.io/cayley/query-languages/gephigraphstream).

## API v1

Unless otherwise noted, all URIs take a POST command.

### Queries and Results

#### `/api/v1/query/gizmo`

POST Body: Javascript source code of the query

Response: JSON results, depending on the query.

#### `/api/v1/query/graphql`

POST Body: [GraphQL](https://cayley.gitbook.io/cayley/query-languages/graphql) query

Response: JSON results, depending on the query.

#### `/api/v1/query/mql`

POST Body: JSON MQL query

Response: JSON results, with a query wrapper:

```javascript
{
    "result": <JSON Result set>
}
```

If the JSON is invalid or an error occurs:

```javascript
{
    "error": "Error message"
}
```

### Query Shapes

Result form:

```javascript
{
    "nodes": [{
        "id" : integer,
        "tags": ["list of tags from the query"],
        "values": ["known values from the query"],
        "is_link_node": bool,  // Does the node represent the link or the node (the oval shapes)
        "is_fixed": bool  // Is the node a fixed starting point of the query
    }],

    "links": [{
        "source": integer,  // Node ID
        "target": integer,  // Node ID
        "link_node": integer  // Node ID
    }]
}
```

#### `/api/v1/shape/gizmo`

POST Body: Javascript source code of the query

Response: JSON description of the last query executed.

#### `/api/v1/shape/mql`

POST Body: JSON MQL query

Response: JSON description of the query.

### Write commands

Responses come in the form

200 Success:

```javascript
{
    "result": "Success message."
}
```

400 / 500 Error:

```javascript
{
    "error": "Error message."
}
```

#### `/api/v1/write`

POST Body: JSON quads

```javascript
[{
    "subject": "Subject Node",
    "predicate": "Predicate Node",
    "object": "Object node",
    "label": "Label node"  // Optional
}]   // More than one quad allowed.
```

Response: JSON response message

#### `/api/v1/write/file/nquad`

POST Body: Form-encoded body:

* Key: `NQuadFile`, Value: N-Quad file to write.

Response: JSON response message

Example:

```
curl http://localhost:64210/api/v1/write/file/nquad -F NQuadFile=@30k.n3
```

#### `/api/v1/delete`

POST Body: JSON quads

```javascript
[{
    "subject": "Subject Node",
    "predicate": "Predicate Node",
    "object": "Object node",
    "label": "Label node"  // Optional
}]   // More than one quad allowed.
```

Response: JSON response message.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cayley.gitbook.io/cayley/usage/http.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
