Gestión de colecciones

Estos endpoints de acción administran una colección existente dentro de una base de datos.

Autenticación

Requiere Api-Key y Api-Secret, o un token Glue de owner cuando el propietario de la base de datos está permitido.

Obtener colección

curl -X GET "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users" \
  -H "Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d" \
  -H "Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf"
GET /v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users HTTP/1.1
Host: api.hola.cloud
Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d
Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf
package main

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

func main() {
	req, err := http.NewRequest("GET", "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
	req.Header.Set("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")

	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/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => [
        'Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d',
        'Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf',
    ],
]);

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

echo $response;
import requests

headers = {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf",
}

response = requests.request(
    "GET",
    "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users",
    headers=headers
)

print(response.text)
const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users", {
  method: "GET",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf"
  }
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users", {
  method: "GET",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf"
  }
});

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/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .header("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
            .header("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")
            .build();

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

Respuesta:

1{"name":"users","total":5400,"indexes":2,"defaults":{"id":"uuid()"}}

Eliminar colección

curl -X POST "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection" \
  -H "Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d" \
  -H "Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf"
POST /v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection HTTP/1.1
Host: api.hola.cloud
Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d
Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf
package main

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

func main() {
	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
	req.Header.Set("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")

	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/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d',
        'Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf',
    ],
]);

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

echo $response;
import requests

headers = {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf",
}

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection",
    headers=headers
)

print(response.text)
const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection", {
  method: "POST",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf"
  }
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection", {
  method: "POST",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf"
  }
});

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/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:dropCollection"))
            .method("POST", HttpRequest.BodyPublishers.noBody())
            .header("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
            .header("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")
            .build();

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

Las respuestas correctas tienen cuerpo vacío.

Definir defaults

Los defaults se mezclan con documentos nuevos al insertarlos. Envía null para eliminar el default de un campo.

curl -X POST "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults" \
  -H "Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d" \
  -H "Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf" \
  -H "Content-Type: application/json" \
  -d '{"id":"uuid()","status":"active","legacy":null}'
POST /v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults HTTP/1.1
Host: api.hola.cloud
Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d
Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf
Content-Type: application/json

{"id":"uuid()","status":"active","legacy":null}
package main

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

func main() {
	payload := map[string]any{"id": "uuid()", "legacy": nil, "status": "active"}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
	req.Header.Set("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")
	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 = ['id' => 'uuid()', 'legacy' => null, 'status' => 'active'];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d',
        'Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf',
        '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": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf",
    "Content-Type": "application/json",
}

payload = {"id": "uuid()", "legacy": None, "status": "active"}
body = json.dumps(payload)

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults",
    headers=headers,
    data=body
)

print(response.text)
const payload = {"id": "uuid()", "legacy": null, "status": "active"};

const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults", {
  method: "POST",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});

console.log(await response.text());
const payload = {"id": "uuid()", "legacy": null, "status": "active"};

const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults", {
  method: "POST",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf",
    "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("id", "uuid()", "legacy", null, "status", "active");
        var body = new ObjectMapper().writeValueAsString(payload);

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:setDefaults"))
            .method("POST", HttpRequest.BodyPublishers.ofString(body))
            .header("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
            .header("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")
            .header("Content-Type", "application/json")
            .build();

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

Respuesta:

1{"id":"uuid()","status":"active"}

Tamaño

size es experimental y devuelve métricas de almacenamiento de la colección.

curl -X POST "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size" \
  -H "Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d" \
  -H "Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf"
POST /v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size HTTP/1.1
Host: api.hola.cloud
Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d
Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf
package main

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

func main() {
	req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size", nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
	req.Header.Set("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")

	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/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Api-Key: 1abbe476-6ad6-4b97-9cca-6deb6ab2901d',
        'Api-Secret: 4bda6d52-762b-4e5d-bed7-85614c13b8bf',
    ],
]);

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

echo $response;
import requests

headers = {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf",
}

response = requests.request(
    "POST",
    "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size",
    headers=headers
)

print(response.text)
const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size", {
  method: "POST",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf"
  }
});

console.log(await response.text());
const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size", {
  method: "POST",
  headers: {
    "Api-Key": "1abbe476-6ad6-4b97-9cca-6deb6ab2901d",
    "Api-Secret": "4bda6d52-762b-4e5d-bed7-85614c13b8bf"
  }
});

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/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users:size"))
            .method("POST", HttpRequest.BodyPublishers.noBody())
            .header("Api-Key", "1abbe476-6ad6-4b97-9cca-6deb6ab2901d")
            .header("Api-Secret", "4bda6d52-762b-4e5d-bed7-85614c13b8bf")
            .build();

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

Respuesta:

1{"memory":123456,"disk":234567,"index.id":12345}

Comentarios

Deja un comentario