Crear Colección
Crea una nueva colección en el nodo KVNode.
Autenticación
Requiere autenticación interna. Pasa las credenciales mediante el encabezado X-Glue-Authentication, o los encabezados apikey y secret.
Cuerpo de la Solicitud
1{
2 "name": "usuarios"
3}
Ejemplo de Solicitud
curl -X POST "https://api.hola.cloud/v1/collections" \
-H "X-Glue-Authentication: TU_TOKEN_AUTH" \
-H "Content-Type: application/json" \
-d '{
"name": "usuarios"
}'POST /v1/collections HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: TU_TOKEN_AUTH
Content-Type: application/json
{
"name": "usuarios"
}// Go 1.21+, standard library only. Save as main.go and run: go run main.go
package main
import (
"fmt"
"io"
"net/http"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"name": "usuarios"}
bodyBytes, err := json.Marshal(payload)
if err != nil {
panic(err)
}
body := string(bodyBytes)
req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/collections", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("X-Glue-Authentication", "TU_TOKEN_AUTH")
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(resp.Status)
fmt.Println(string(responseBody))
}
<?php
// PHP 8+ with the curl extension. Save as example.php and run: php example.php
$payload = ['name' => 'usuarios'];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/collections',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'X-Glue-Authentication: TU_TOKEN_AUTH',
'Content-Type: application/json',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $response, "\n";
curl_close($ch);
# Python 3.8+. Install: pip install requests. Save as example.py and run: python example.py
import requests
headers = {
"X-Glue-Authentication": "TU_TOKEN_AUTH",
"Content-Type": "application/json",
}
payload = {"name": "usuarios"}
response = requests.request(
"POST",
"https://api.hola.cloud/v1/collections",
headers=headers,
json=payload
)
print(response.status_code)
print(response.text)
// Node.js 18+. Save as example.mjs and run: node example.mjs
const payload = {"name": "usuarios"};
const response = await fetch("https://api.hola.cloud/v1/collections", {
method: "POST",
headers: {
"X-Glue-Authentication": "TU_TOKEN_AUTH",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(response.status);
console.log(await response.text());
const payload = {"name": "usuarios"};
const response = await fetch("https://api.hola.cloud/v1/collections", {
method: "POST",
headers: {
"X-Glue-Authentication": "TU_TOKEN_AUTH",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(response.status);
console.log(await response.text());
// Java 17+, standard library only. Save as Main.java and run: java Main.java
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 body = """
{
"name": "usuarios"
}
""";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/collections"))
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.header("X-Glue-Authentication", "TU_TOKEN_AUTH")
.header("Content-Type", "application/json")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}Ejemplo de Respuesta
1HTTP/1.1 200 OK
2Content-Type: application/json
1{
2 "ok": true,
3 "collection": "usuarios"
4}
Códigos de Error
| Estado | Código | Descripción |
|---|---|---|
| 400 | invalid_json | Nombre de colección faltante o inválido |
| 403 | forbidden | Missing authentication headers |
| 409 | conflict | La colección ya existe |
| 500 | internal_error | Error interno del servidor |
Comentarios