Keyboard shortcuts

Press โ† or โ†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

serve

Start the local HTTP API server.

xrat serve [flags]

Flags

FlagDescription
--host <host>Override HTTP API bind host
--port <port>Override HTTP API bind port

Examples

Start with default settings (from config.toml):

xrat serve

Override host and port:

xrat serve --host 0.0.0.0 --port 9090

Configuration

The HTTP API server is configured in config.toml:

[server]
enabled = false
host = "127.0.0.1"
port = 8080
key = { env = "XRAT_API_KEY" }
FieldDescription
enabledEnable daemon-hosted API (see below)
hostBind host (default: 127.0.0.1)
portBind port (default: 8080)
keyOptional API key for authentication

Operating Modes

Foreground Mode

Run xrat serve to start the API server in the foreground. Useful for development or standalone deployment.

Daemon-Hosted Mode

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.

systemd Service

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

API Routes

RouteMethodDescription
/healthGETHealth check (no auth required)
/jsonGETList configs with latest test results as JSON array
/b64GETBase64-encoded subscription text payload
/configsGETPaginated config list with details
/configs/{id}GETSingle config detail with latest test results

Query Parameters

/json

ParameterDescription
keyAPI key (if authentication is enabled)
topReturn top N configs sorted by real-delay
enabledFilter: true for enabled configs only
protocolFilter by protocol: vless, vmess, ss, trojan, hy2

/b64

ParameterDescription
keyAPI key (if authentication is enabled)

/configs

ParameterDescription
keyAPI key (if authentication is enabled)
pagePage number (default: 1)
per_pageItems per page (default: 20)
enabledFilter: true for enabled configs only
protocolFilter by protocol

/configs/{id}

ParameterDescription
keyAPI key (if authentication is enabled)

Authentication

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"

Response Formats

/health

{
  "status": "ok"
}

/json

[
  {
    "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"
    }
  }
]

/b64

Returns base64-encoded subscription text compatible with v2rayN, Clash, and other clients:

dmxlc3M6Ly91dWlkQGV4YW1wbGUuY29tOjQ0Mz90eXBlPXdzJnNlY3VyaXR5PXRscyNNeSBOb2RlCnZtZXNzOi8v...

/configs

{
  "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": { ... }
    }
  ]
}

/configs/{id}

{
  "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": { ... }
}

Use Cases

  • Subscription server: Serve configs to mobile/desktop clients via /b64
  • Monitoring: Poll /health and /configs for uptime monitoring
  • Integration: Build dashboards or automation around /json and /configs
  • Proxy management: Query active configs and test results programmatically
  • daemon โ€” daemon-hosted API mode
  • test โ€” test results are exposed via the API
  • list โ€” CLI equivalent of /configs