Obtener documento
Obtiene un documento por id. La búsqueda usa un índice map sobre el campo id cuando existe; si no, cae a un escaneo de colección.
Autenticación
Requiere Api-Key y Api-Secret, o un token Glue de owner cuando el propietario de la base de datos está permitido.
Solicitud HTTP
curl -X GET "https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users/documents/user-1" \
-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/documents/user-1 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/documents/user-1", 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/documents/user-1',
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/documents/user-1",
headers=headers
)
print(response.text)
const response = await fetch("https://api.hola.cloud/v1/databases/a1b2c3d4-e5f6-7890-abcd-ef1234567890/collections/users/documents/user-1", {
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/documents/user-1", {
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/documents/user-1"))
.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{
2 "id": "user-1",
3 "document": {"id":"user-1","name":"Alice","role":"admin"},
4 "source": {"type":"index","name":"id"}
5}
source se omite cuando el endpoint usa escaneo de colección. IDs vacíos devuelven 400 Bad Request; colecciones o documentos inexistentes devuelven 404 Not Found.
Comentarios