# API Endpoints

## Statistics

<mark style="color:blue;">`GET`</mark> `http://<host>:8181/api/stats`

This endpoint allows you to get storage statistics of the running Akumuli instance. It's also can be used as a test endpoint to test service availability.<br>

{% tabs %}
{% tab title="200 Storage statistics successfully retrieved." %}

```javascript
{    "volume_0":    {        "free_space": "0",        "file_name": "\/root\/.akumuli\/db_0.vol"    },    "volume_1":    {        "free_space": "0",        "file_name": "\/root\/.akumuli\/db_1.vol"    },    "volume_2":    {        "free_space": "0",        "file_name": "\/root\/.akumuli\/db_2.vol"    },    "volume_3":    {        "free_space": "2027974656",        "file_name": "\/root\/.akumuli\/db_3.vol"    }}
```

{% endtab %}
{% endtabs %}

## Read query

<mark style="color:green;">`POST`</mark> `http://<host>:8181/api/query`

This endpoint allows you to retrieve time-series data from the database. The client should provide valid query. The response will use chunked transfer encoding to return the results. The results are encoded using the RESP protocol.

#### Request Body

| Name       | Type   | Description        |
| ---------- | ------ | ------------------ |
| Query Body | object | JSON encoded query |

{% tabs %}
{% tab title="200 " %}

```
+RESP encoded data
+just like this
```

{% endtab %}

{% tab title="400 " %}

```
-RESP encoded error message
```

{% endtab %}
{% endtabs %}

## Search

<mark style="color:green;">`POST`</mark> `http://<host>:8181/api/search`

This API endpoint can be used to retreive the metadata like series names and tag values.

#### Path Parameters

| Name       | Type   | Description        |
| ---------- | ------ | ------------------ |
| Query Body | string | JSON encoded query |

{% tabs %}
{% tab title="200 " %}

```
+RESP encoded output
```

{% endtab %}

{% tab title="400 " %}

```
-RESP encoded error message
```

{% endtab %}
{% endtabs %}

## Suggest

<mark style="color:green;">`POST`</mark> `http://<host>:8181/api/suggest`

This endpoint can be used to retrieve metric names, tag names, and tag values. It powers autocomplete function of the **akumuli-datasource** for Grafana.&#x20;

#### Path Parameters

| Name       | Type   | Description        |
| ---------- | ------ | ------------------ |
| Query Body | string | JSON encoded query |

{% tabs %}
{% tab title="200 " %}

```
+RESP encoded list or results
```

{% endtab %}

{% tab title="400 " %}

```
-RESP encoded error message
```

{% endtab %}
{% endtabs %}

## List functions

<mark style="color:blue;">`GET`</mark> `http://<host>:8181/api/function-names`

This endpoint can be used to retrieve the list of functions that can be used in queries.

{% tabs %}
{% tab title="200 List of functions" %}

```

absaccumulatecmacusumdiffdivideewmaewma-errorfrequent-itemsheavy-hittersmultiplyratescalesmasma-errorsumtop
```

{% endtab %}
{% endtabs %}
