Quick Start Guide with InceptionDB

This guide creates a collection, inserts three JSON documents, and queries filtered documents.

Database access endpoints accept Api-Key and Api-Secret headers. A Glue owner token can also be used where the database owner is allowed.

Step 1: Create a Collection

curl -X POST "https://api.hola.cloud/v1/databases/your-database-id/collections" \
  -H "Api-Key: your-api-key" \
  -H "Api-Secret: your-api-secret" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-collection"
  }'
POST /v1/databases/your-database-id/collections HTTP/1.1
Host: api.hola.cloud
Api-Key: your-api-key
Api-Secret: your-api-secret
Content-Type: application/json

{
    "name": "my-collection"
  }
package main

import (
	"fmt"
	"io"
	"net/http"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"name": "my-collection"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/your-database-id/collections", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "your-api-key")
	req.Header.Set("Api-Secret", "your-api-secret")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['name' => 'my-collection'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/databases/your-database-id/collections',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: your-api-key',
        'Api-Secret: your-api-secret',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

import json

headers = {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/json",
}

payload = {"name": "my-collection"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/databases/your-database-id/collections",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"name": "my-collection"};

const response = await fetch("https://api.hola.cloud/v1/databases/your-database-id/collections", {
  method: "POST",
  headers: {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
const payload = {"name": "my-collection"};

const response = await fetch("https://api.hola.cloud/v1/databases/your-database-id/collections", {
  method: "POST",
  headers: {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("name", "my-collection");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/v1/databases/your-database-id/collections"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", "your-api-key")
            .header("Api-Secret", "your-api-secret")
            .header("Content-Type", "application/json")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Expected response:

1{
2  "name": "my-collection",
3  "total": 0,
4  "indexes": 0,
5  "defaults": {
6    "id": "uuid()"
7  }
8}

Step 2: Insert Documents

Use the collection action endpoint and send JSONL: one JSON document per line.

curl -X POST "https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:insert" \
  -H "Api-Key: your-api-key" \
  -H "Api-Secret: your-api-secret" \
  -H "Content-Type: application/jsonl" \
  --data-binary '{"name":"Element 1","value":100}
{"name":"Element 2","value":200}
{"name":"Element 3","value":300}'
POST /v1/databases/your-database-id/collections/my-collection:insert HTTP/1.1
Host: api.hola.cloud
Api-Key: your-api-key
Api-Secret: your-api-secret
Content-Type: application/jsonl

{"name":"Element 1","value":100}
{"name":"Element 2","value":200}
{"name":"Element 3","value":300}
package main

import (
	"fmt"
	"io"
	"net/http"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"name": "Element 1", "value": 100}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:insert", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "your-api-key")
	req.Header.Set("Api-Secret", "your-api-secret")
	req.Header.Set("Content-Type", "application/jsonl")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['name' => 'Element 1', 'value' => 100];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:insert',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: your-api-key',
        'Api-Secret: your-api-secret',
        'Content-Type: application/jsonl',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

import json

headers = {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/jsonl",
}

payload = {"name": "Element 1", "value": 100}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:insert",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"name": "Element 1", "value": 100};

const response = await fetch("https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:insert", {
  method: "POST",
  headers: {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/jsonl"
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
const payload = {"name": "Element 1", "value": 100};

const response = await fetch("https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:insert", {
  method: "POST",
  headers: {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/jsonl"
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("name", "Element 1", "value", 100);
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:insert"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", "your-api-key")
            .header("Api-Secret", "your-api-secret")
            .header("Content-Type", "application/jsonl")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Expected response:

1{"id":"document-id-1","name":"Element 1","value":100}
2{"id":"document-id-2","name":"Element 2","value":200}
3{"id":"document-id-3","name":"Element 3","value":300}

Step 3: Find Filtered Documents

curl -X POST "https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:find" \
  -H "Api-Key: your-api-key" \
  -H "Api-Secret: your-api-secret" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": {
      "value": { "$gte": 200 }
    }
  }'
POST /v1/databases/your-database-id/collections/my-collection:find HTTP/1.1
Host: api.hola.cloud
Api-Key: your-api-key
Api-Secret: your-api-secret
Content-Type: application/json

{
    "filter": {
      "value": { "$gte": 200 }
    }
  }
package main

import (
	"fmt"
	"io"
	"net/http"
	"encoding/json"
	"strings"
)

func main() {
	payload := map[string]any{"filter": map[string]any{"value": map[string]any{"$gte": 200}}}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:find", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "your-api-key")
	req.Header.Set("Api-Secret", "your-api-secret")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$payload = ['filter' => ['value' => ['$gte' => 200]]];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:find',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: your-api-key',
        'Api-Secret: your-api-secret',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

import json

headers = {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/json",
}

payload = {"filter": {"value": {"$gte": 200}}}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:find",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"filter": {"value": {"$gte": 200}}};

const response = await fetch("https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:find", {
  method: "POST",
  headers: {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
const payload = {"filter": {"value": {"$gte": 200}}};

const response = await fetch("https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:find", {
  method: "POST",
  headers: {
    "Api-Key": "your-api-key",
    "Api-Secret": "your-api-secret",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.List;

public class Main {
    public static void main(String[] args) throws Exception {
        var payload = Map.of("filter", Map.of("value", Map.of("$gte", 200)));
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/v1/databases/your-database-id/collections/my-collection:find"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", "your-api-key")
            .header("Api-Secret", "your-api-secret")
            .header("Content-Type", "application/json")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Expected response:

1{"id":"document-id-2","name":"Element 2","value":200}
2{"id":"document-id-3","name":"Element 3","value":300}

Summary

You created a collection, inserted JSONL documents through :insert, and queried documents through :find.

Comments

Leave a comment