Managing Collections

Collection endpoints use database access credentials: Api-Key and Api-Secret, or a Glue owner token where the database owner is allowed.

Create a Collection

curl -X POST "https://api.hola.cloud/v1/databases/{databaseId}/collections" \
  -H "Api-Key: {api_key}" \
  -H "Api-Secret: {api_secret}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-collection"
  }'
POST /v1/databases/%7BdatabaseId%7D/collections HTTP/1.1
Host: api.hola.cloud
Api-Key: {api_key}
Api-Secret: {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/{databaseId}/collections", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "{api_key}")
	req.Header.Set("Api-Secret", "{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/{databaseId}/collections',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: {api_key}',
        'Api-Secret: {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": "{api_key}",
    "Api-Secret": "{api_secret}",
    "Content-Type": "application/json",
}

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

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/databases/{databaseId}/collections",
    headers=headers,
    data=body
)

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

const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections", {
  method: "POST",
  headers: {
    "Api-Key": "{api_key}",
    "Api-Secret": "{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/{databaseId}/collections", {
  method: "POST",
  headers: {
    "Api-Key": "{api_key}",
    "Api-Secret": "{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/{databaseId}/collections"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", "{api_key}")
            .header("Api-Secret", "{api_secret}")
            .header("Content-Type", "application/json")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
1{
2  "name": "my-collection",
3  "total": 0,
4  "indexes": 0,
5  "defaults": {
6    "id": "uuid()"
7  }
8}

List Collections

curl "https://api.hola.cloud/v1/databases/{databaseId}/collections" \
  -H "Api-Key: {api_key}" \
  -H "Api-Secret: {api_secret}"
GET /v1/databases/%7BdatabaseId%7D/collections HTTP/1.1
Host: api.hola.cloud
Api-Key: {api_key}
Api-Secret: {api_secret}
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	req, err := http.NewRequest("GET", "https://api.hola.cloud/v1/databases/{databaseId}/collections", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "{api_key}")
	req.Header.Set("Api-Secret", "{api_secret}")

	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
$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/databases/{databaseId}/collections',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => [
        'Api-Key: {api_key}',
        'Api-Secret: {api_secret}',
    ],
]);

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

echo $response;
import requests

headers = {
    "Api-Key": "{api_key}",
    "Api-Secret": "{api_secret}",
}

response = requests.request(
    "GET",
    "https://api.hola.cloud/v1/databases/{databaseId}/collections",
    headers=headers
)

print(response.text)
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections", {
  method: "GET",
  headers: {
    "Api-Key": "{api_key}",
    "Api-Secret": "{api_secret}"
  }
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections", {
  method: "GET",
  headers: {
    "Api-Key": "{api_key}",
    "Api-Secret": "{api_secret}"
  }
});

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;

public class Main {
    public static void main(String[] args) throws Exception {
        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/v1/databases/{databaseId}/collections"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .header("Api-Key", "{api_key}")
            .header("Api-Secret", "{api_secret}")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
 1[
 2  {
 3    "name": "my-collection",
 4    "total": 3,
 5    "indexes": 0,
 6    "defaults": {
 7      "id": "uuid()"
 8    }
 9  }
10]

Insert Documents

Collections can receive JSONL documents through the :insert action.

curl -X POST "https://api.hola.cloud/v1/databases/{databaseId}/collections/my-collection:insert" \
  -H "Api-Key: {api_key}" \
  -H "Api-Secret: {api_secret}" \
  -H "Content-Type: application/jsonl" \
  --data-binary '{"id":"1","name":"Alfonso"}
{"id":"2","name":"Gerardo"}'
POST /v1/databases/%7BdatabaseId%7D/collections/my-collection:insert HTTP/1.1
Host: api.hola.cloud
Api-Key: {api_key}
Api-Secret: {api_secret}
Content-Type: application/jsonl

{"id":"1","name":"Alfonso"}
{"id":"2","name":"Gerardo"}
package main

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

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

	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/{databaseId}/collections/my-collection:insert", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "{api_key}")
	req.Header.Set("Api-Secret", "{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 = ['id' => '1', 'name' => 'Alfonso'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/databases/{databaseId}/collections/my-collection:insert',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: {api_key}',
        'Api-Secret: {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": "{api_key}",
    "Api-Secret": "{api_secret}",
    "Content-Type": "application/jsonl",
}

payload = {"id": "1", "name": "Alfonso"}
body = json.dumps(payload)

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

print(response.text)
const payload = {"id": "1", "name": "Alfonso"};

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

console.log(await response.text());
const payload = {"id": "1", "name": "Alfonso"};

const response = await fetch("https://api.hola.cloud/v1/databases/{databaseId}/collections/my-collection:insert", {
  method: "POST",
  headers: {
    "Api-Key": "{api_key}",
    "Api-Secret": "{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("id", "1", "name", "Alfonso");
        var body = new ObjectMapper().writeValueAsString(payload);

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

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

The response is JSONL with the inserted documents.

1{"id":"1","name":"Alfonso"}
2{"id":"2","name":"Gerardo"}

Comments

Leave a comment