HTTP

Before using the HTTP API, make sure at least one node has the HTTP API port enabled. By default the API port is disabled, this can be changed by setting http_api_port in the configuration file or by setting the SIRIDB_HTTP_API_PORT environment variable.

The API has support for both JSON and qpack and can be used to perform service requests, inserts and queries.

Headers

The header field Content-Type is required and needs application/json or application/qpack.

Authentication

The HTTP API has supports for basic authentication.

In the examples below we use the default service account sa:siri (c2E6c2lyaQ== when base64 encoded) and the default database user iris:siri (aXJpczpzaXJp when base64 encoded)

URIs

The following URIs are available.

Service requests:

Query request:

Insert request:

Examples

Service request

Creating a new database using curl with basic authentication:

new-database

curl --location --request POST 'http://siridb-server-1:9020/new-database' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ==' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"dbname": "sampledb",
	"time_precision": "s",
	"buffer_size": 8192,
	"duration_num": "1w",
	"duration_log": "3d"
}'

Possible response

    "OK"

new-account

curl --location --request POST 'http://siridb-server-1:9020/new-account' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ==' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"account": "bob",
    "password": "passwd4bob"
}'

Possible response

    "OK"

change-password

curl --location --request POST 'http://siridb-server-1:9020/change-password' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ==' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"account": "bob",
    "password": "pass"
}'

Possible response

    "OK"

drop-account

curl --location --request POST 'http://siridb-server-1:9020/drop-account' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ==' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"account": "bob"
}'

Possible response

    "OK"

new-pool

curl --location --request POST 'http://siridb-server-3:9020/new-pool' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ==' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"dbname": "sampledb",
    "username": "iris",
    "password": "siri",
    "host": "siridb-server-1",
    "port": 9000
}'

Possible response

    "OK"

new-replica

curl --location --request POST 'http://siridb-server-2:9020/new-replica' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ==' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"dbname": "sampledb",
    "username": "iris",
    "password": "siri",
    "host": "siridb-server-1",
    "port": 9000,
    "pool": 0
}'

Possible response

    "OK"

drop-database

curl --location --request POST 'http://siridb-server-1:9020/drop-database' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ==' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"database": "sampledb",
    "ignore_offline": false
}'

Possible response

    "OK"

get-version

curl --location --request GET 'http://siridb-server-1:9020/get-version' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ=='

Possible response

    ["2.0.36"]

get-accounts

curl --location --request GET 'http://siridb-server-1:9020/get-accounts' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ=='

Possible response

    ["sa","bob"]

get-databases

curl --location --request GET 'http://siridb-server-1:9020/get-databases' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic c2E6c2lyaQ=='

Possible response

    ["sampledb"]

Query request

Selecting the number of points in a certain series called ‘aggr’.

curl --location --request POST 'http://siridb-server-1:9020/query/dbtest' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic aXJpczpzaXJp' \
--header 'Content-Type: text/plain' \
--data-raw '{
	"q": "select count() from '\''aggr'\''",
	"t": "ms"
}'

Possible response

    {"aggr":[
            [1588450390000,23]
        ]
    }

An optional {"t": "<TIME_PRECISION>"} may be used, where <TIME_PRECISION> can be s, ms, us or ns. (seconds, milliseconds, microseconds or nanoseconds). If it is not provided then the timestamp precision is set to the database default.

Insert request

Inserting two points in a series.

curl --location --request POST 'http://siridb-server-1:9020/insert/dbtest' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic aXJpczpzaXJp' \
--header 'Content-Type: text/plain' \
--data-raw '{
    "my-example-serie": [
        [1578933215, 42],
        [1578933223, 123]
    ]
}'

Possible response

    {"success_msg":"Successfully inserted 2 point(s)."}