Connections API

A connection is a link to an Indexima cluster.
Connection API makes it possible to create Connections and execute SQL statements through HTTP requests.

Node: This API is available on your Developer Console server, the prefix url is /api/v1

HTTP Routes

Retrieve all connections

GET /connections

Create a new connection

POST /connections

The request body should contain the connection object in JSON that we want to create.

Input example with a Basic Authentication:

json body

{
  name: "MyFirstConnection",
  url: "indexima.my-server.io:10000/default",
  username: "my_user",
  password: "********",
  impersonate: false
}
JS

If the status code is 200, the return is just a generated id.

Retrieve a connection

GET /connections/:id

 Return a connection for a given id.

Delete a connection

DELETE /connections/:id

Delete a connection for a given id.

Connection properties

NameTypeDescription
idStringGenerated unique ID (assigned on creation).
creatorStringUsername of creator (assigned on creation).
nameStringDisplay the name of the connection.
urlStringJDBC URL to the target cluster.
usernameStringUsername for basic authentication or impersonation.
passwordStringPassword for basic authentication.
impersonateBooleanIf true, enable impersonation.

Execute SQL statements

Execute a single query

POST /api/query

Execute SQL statements through a connection.

Statements must be contained in a JSON object as the value of the key "query".

Authorization and ConnectionId must be present in headers.

Input example:

json body

{
  query: "SELECT * FROM countries_table LIMIT 5"
}
JS

The JSON return object contains all the statement's results.

Output example:

json return body

{"outputs":[{"columns":["country","population"],"results":[["France",66000000],["Spain",46000000],["Italy",60000000],["Germany",83000000],["Switzerland",8500000]],"outputs":[]}]}
JS

Complete example with httpie

Execute query with httpie

URL=localhost:8082

# Login
TOKEN=$(http POST ${URL}/api/login name=admin password=password |jq -r .id)
echo ${TOKEN}

# Get Id of the first connection
CONNECTION_ID=$(http GET ${URL}/api/v1/connections \
  Authorization:${TOKEN} |jq -r '.[0]'.id)
echo $CONNECTION_ID

# Execute query
http POST ${URL}/api/query Authorization:${TOKEN} ConnectionId:${CONNECTION_ID} query="SELECT 1"
BASH

Execute one or multiple queries asynchronously

POST /api/query/async

Execute SQL statements through a connection. Instead of waiting for the result, this route returns a poolId of queries. The queries then run in the background.

Statements must be contained in a JSON object as the value of the key "query". Multiple queries are separated by a semi-colon

Authorization and ConnectionId must be present in headers.

The JSON return object contains the poolId and each query id.

Input example

json body

{
  query: "SELECT 1 ; SELECT 2"
}
JS

Return example

json return body

{
    "poolId": "36e127b5-ce41-431c-ad7a-dd60871da721",
    "queries": [
        {
            "id": "dc5d94c0-b719-46c6-9250-6527a8005312",
            "query": "SELECT 1"
        },
        {
            "id": "5136a022-5200-4e41-b485-55b77b7a6bc6",
            "query": "SELECT 2"
        }
    ]
}
JS

Complete example with httpie and jq

Execute query with httpie

URL=localhost:8082

# Login
TOKEN=$(http POST ${URL}/api/login name=admin password=password |jq -r .id)
echo ${TOKEN}

# Get Id of the first connection
CONNECTION_ID=$(http GET ${URL}/api/v1/connections \
  Authorization:${TOKEN} |jq -r '.[0]'.id)
echo $CONNECTION_ID

# Execute query
http POST ${URL}/api/query/async Authorization:${TOKEN} ConnectionId:${CONNECTION_ID} query="SELECT 1 ; SELECT 2"
BASH