⚙️ Config

集中化配置管理

Config 存储用户级 JSON 配置条目,并暴露 v0 和 v1 HTTP API。

Config

核心功能

读取和更新配置 map,而无需为应用额外构建配置服务。

用户配置

使用 GET /v1/config 和 PATCH /v1/config 管理认证用户的配置。

Entries Map

将配置存储为 JSON entries,包括字符串、数字、布尔值和嵌套对象。

Legacy v0 配置

需要时可管理带有 id 和 entries 字段的 v0 配置文档。

Quick start

快速开始

使用 API 在几秒内开始使用 Config。

curl -X PATCH https://config.hola.cloud/v1/config \
  -H 'X-Glue-Authentication: {"user":{"id":"user-123"}}' \
  -d '{"database.url":"postgres://prod:5432/db","feature.enabled":true}'
PATCH /v1/config HTTP/1.1
Host: config.hola.cloud
X-Glue-Authentication: {"user":{"id":"user-123"}}

{"database.url":"postgres://prod:5432/db","feature.enabled":true}
// 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{"database.url": "postgres://prod:5432/db", "feature.enabled": true}
	bodyBytes, err := json.Marshal(payload)
	if err != nil {
		panic(err)
	}
	body := string(bodyBytes)

	req, err := http.NewRequest("PATCH", "https://config.hola.cloud/v1/config", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "{\"user\":{\"id\":\"user-123\"}}")

	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 = ['database.url' => 'postgres://prod:5432/db', 'feature.enabled' => true];
$body = json_encode($payload);

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://config.hola.cloud/v1/config',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: {"user":{"id":"user-123"}}',
    ],
]);

$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": "{\"user\":{\"id\":\"user-123\"}}",
}

payload = {"database.url": "postgres://prod:5432/db", "feature.enabled": True}

response = requests.request(
    "PATCH",
    "https://config.hola.cloud/v1/config",
    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 = {"database.url": "postgres://prod:5432/db", "feature.enabled": true};

const response = await fetch("https://config.hola.cloud/v1/config", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "{\"user\":{\"id\":\"user-123\"}}"
  },
  body: JSON.stringify(payload)
});

console.log(response.status);
console.log(await response.text());
const payload = {"database.url": "postgres://prod:5432/db", "feature.enabled": true};

const response = await fetch("https://config.hola.cloud/v1/config", {
  method: "PATCH",
  headers: {
    "X-Glue-Authentication": "{\"user\":{\"id\":\"user-123\"}}"
  },
  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 = """
{"database.url":"postgres://prod:5432/db","feature.enabled":true}
""";

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://config.hola.cloud/v1/config"))
            .method("PATCH", HttpRequest.BodyPublishers.ofString(body))
            .header("X-Glue-Authentication", "{\"user\":{\"id\":\"user-123\"}}")
            .build();

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

常见用例

微服务编排

Build and deploy with Config on HolaCloud's enterprise platform, designed for security, reliability, and scale.

数据管道自动化

Build and deploy with Config on HolaCloud's enterprise platform, designed for security, reliability, and scale.

事件驱动架构

Build and deploy with Config on HolaCloud's enterprise platform, designed for security, reliability, and scale.

后端 API 开发

Build and deploy with Config on HolaCloud's enterprise platform, designed for security, reliability, and scale.

Ready to get started?

Explore the documentation or launch the console to start building with Config.

评论

发表评论