Start the local HTTP API server.
xrat serve [flags]| Flag | Description |
|---|---|
--host <host> |
Override HTTP API bind host |
--port <port> |
Override HTTP API bind port |
Start with default settings (from config.toml):
xrat serveOverride host and port:
xrat serve --host 0.0.0.0 --port 9090The HTTP API server is configured in config.toml:
[server]
enabled = false
host = "127.0.0.1"
port = 18203
key = { env = "XRAT_API_KEY" }| Field | Description |
|---|---|
enabled |
Enable daemon-hosted API (see below) |
host |
Bind host (default: 127.0.0.1) |
port |
Bind port (default: 18203) |
key |
Optional API key for authentication |
Run xrat serve to start the API server in the foreground. Useful for
development or standalone deployment.
When enabled = true in config.toml, the daemon automatically starts the HTTP
API alongside IPC. The API runs in the same process as the daemon.
Run as a systemd user service:
[Unit]
Description=xrat HTTP API
After=network.target
[Service]
ExecStart=/usr/local/bin/xrat serve
Restart=on-failure
Environment=RUST_LOG=info
[Install]
WantedBy=default.target| Route | Method | Description |
|---|---|---|
/health |
GET | Health check (no auth required) |
/json |
GET | List configs with latest test results as JSON array |
/b64 |
GET | Base64-encoded subscription text payload |
/configs |
GET | Paginated config list with details |
/configs/{id} |
GET | Single config detail with latest test results |
| Parameter | Description |
|---|---|
key |
API key (if authentication is enabled) |
top |
Return top N configs sorted by real-delay |
enabled |
Filter: true for enabled configs only |
protocol |
Filter by protocol: vless, vmess, ss, trojan, hy2 |
| Parameter | Description |
|---|---|
key |
API key (if authentication is enabled) |
| Parameter | Description |
|---|---|
key |
API key (if authentication is enabled) |
page |
Page number (default: 1) |
per_page |
Items per page (default: 20) |
enabled |
Filter: true for enabled configs only |
protocol |
Filter by protocol |
| Parameter | Description |
|---|---|
key |
API key (if authentication is enabled) |
If key is set in config.toml, all routes except /health require the key
query parameter:
curl "http://localhost:8080/json?key=secret"curl "http://localhost:8080/configs?key=secret&page=1&per_page=10"{
"status": "ok"
}[
{
"id": 42,
"protocol": "vless",
"address": "example.com",
"port": 443,
"name": "My Node",
"is_enabled": true,
"is_active": false,
"latest_test": {
"icmp_ok": true,
"icmp_ms": 15,
"tcp_ok": true,
"tcp_ms": 12,
"real_delay_ok": true,
"real_delay_ms": 145,
"download_mbps": null,
"tested_at": "2026-05-28T10:00:00Z"
}
}
]Returns base64-encoded subscription text compatible with v2rayN, Clash, and other clients:
dmxlc3M6Ly91dWlkQGV4YW1wbGUuY29tOjQ0Mz90eXBlPXdzJnNlY3VyaXR5PXRscyNNeSBOb2RlCnZtZXNzOi8v...
{
"page": 1,
"per_page": 20,
"total": 150,
"configs": [
{
"id": 42,
"protocol": "vless",
"address": "example.com",
"port": 443,
"name": "My Node",
"is_enabled": true,
"is_active": false,
"subscription_id": 1,
"created_at": "2026-05-20T08:00:00Z",
"updated_at": "2026-05-28T10:00:00Z",
"latest_test": { ... }
}
]
}{
"id": 42,
"protocol": "vless",
"address": "example.com",
"port": 443,
"uuid": "uuid-123",
"network": "ws",
"tls": "tls",
"sni": "cdn.example.com",
"host": "cdn.example.com",
"path": "/ray",
"name": "My Node",
"is_enabled": true,
"is_active": false,
"subscription_id": 1,
"created_at": "2026-05-20T08:00:00Z",
"updated_at": "2026-05-28T10:00:00Z",
"latest_test": { ... }
}- Subscription server: Serve configs to mobile/desktop clients via
/b64 - Monitoring: Poll
/healthand/configsfor uptime monitoring - Integration: Build dashboards or automation around
/jsonand/configs - Proxy management: Query active configs and test results programmatically