4.6. REST API

4.6. REST API

4.6.1. Requirements

Before you can get started, please ensure that:

  • You have the latest version of the QuasarDB client library installed on your computer

  • You have access to a running QuasarDB cluster.

The rest of this document assumes you have a cluster up and running under qdb://127.0.0.1:2836.

4.6.2. Connection management

Establishing a connection with the QuasarDB cluster is easy. You need the URI of at least one of your nodes, and the client will automatically detect all nodes in the cluster.

A QuasarDB cluster operates in either a secure or an insecure mode. If you do not know whether your cluster is running in secure mode, please ask your system administrator.

4.6.2.1. Insecure connection

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"username": "$USERNAME", "secret_key": "$SECRET"}' \
  http://127.0.0.1:40080/api/login

4.6.2.2. Secure connection

In case of a secure connection, we need to provide a few additional parameters:

  • A username;

  • A user private key;

  • A cluster public key.

More information on QuasarDB’s security mechanisms can be found in our security manual.

If you do not know the values of these parameters, please ask your system administrator.

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"username": "$USERNAME", "secret_key": "$SECRET"}' \
  http://127.0.0.1:40080/api/login

4.6.3. Queries

If you are looking for more flexible control over the kind of calculations performed on a dataset, or want to push certain computations to the cluster, QuasarDB offers an SQL-like query language for you to interact with your data. Please see our query language documentation.

In the example below, we will show you how to execute a simple query that calculates to total traded volume for the entire dataset.

curl \
  -X POST \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{ "query": "SELECT SUM(volume) FROM stocks" }' \
  http://127.0.0.1:40080/api/query