复制
从父节点复制数据到此 KVNode。
身份验证
需要内部身份验证。通过 X-Glue-Authentication 头部或 apikey 和 secret 头部传递凭据。
请求示例
curl -X POST "https://api.hola.cloud/v1/replicate" \
-H "X-Glue-Authentication: YOUR_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"entries": [
{
"collection": "users",
"key": "user:1001",
"value": {"name": "Alice"},
"seq": 42
}
]
}'POST /v1/replicate HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: YOUR_AUTH_TOKEN
Content-Type: application/json
{
"entries": [
{
"collection": "users",
"key": "user:1001",
"value": {"name": "Alice"},
"seq": 42
}
]
}package main
import (
"fmt"
"io"
"net/http"
"encoding/json"
"strings"
)
func main() {
payload := map[string]any{"entries": []any{map[string]any{"collection": "users", "key": "user:1001", "seq": 42, "value": map[string]any{"name": "Alice"}}}}
bodyBytes, err := json.Marshal(payload)
if err != nil {
panic(err)
}
body := string(bodyBytes)
req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/replicate", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("X-Glue-Authentication", "YOUR_AUTH_TOKEN")
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 = ['entries' => [['collection' => 'users', 'key' => 'user:1001', 'seq' => 42, 'value' => ['name' => 'Alice']]]];
$body = json_encode($payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/replicate',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'X-Glue-Authentication: YOUR_AUTH_TOKEN',
'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 = {
"X-Glue-Authentication": "YOUR_AUTH_TOKEN",
"Content-Type": "application/json",
}
payload = {"entries": [{"collection": "users", "key": "user:1001", "seq": 42, "value": {"name": "Alice"}}]}
body = json.dumps(payload)
response = requests.request(
"POST",
"https://api.hola.cloud/v1/replicate",
headers=headers,
data=body
)
print(response.text)
const payload = {"entries": [{"collection": "users", "key": "user:1001", "seq": 42, "value": {"name": "Alice"}}]};
const response = await fetch("https://api.hola.cloud/v1/replicate", {
method: "POST",
headers: {
"X-Glue-Authentication": "YOUR_AUTH_TOKEN",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
console.log(await response.text());
const payload = {"entries": [{"collection": "users", "key": "user:1001", "seq": 42, "value": {"name": "Alice"}}]};
const response = await fetch("https://api.hola.cloud/v1/replicate", {
method: "POST",
headers: {
"X-Glue-Authentication": "YOUR_AUTH_TOKEN",
"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("entries", List.of(Map.of("collection", "users", "key", "user:1001", "seq", 42, "value", Map.of("name", "Alice"))));
var body = new ObjectMapper().writeValueAsString(payload);
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/replicate"))
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.header("X-Glue-Authentication", "YOUR_AUTH_TOKEN")
.header("Content-Type", "application/json")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}响应示例
1HTTP/1.1 200 OK
2Content-Type: application/json
1{
2 "ok": true,
3 "applied": 1
4}
错误代码
| 状态 | 代码 | 描述 |
|---|---|---|
| 400 | invalid_json | 无效的 JSON payload |
| 403 | forbidden | 缺少认证头部 |
| 502 | parent_unavailable | 父节点不可达 |
| 500 | internal_error | 服务器内部错误 |
评论