Files
2026-11-22 14:21:54 +01:00

41 lines
2.4 KiB
Markdown

# REST API (`/api/v1`)
Bearer tokens (`Authorization: Bearer <token>`); roles: `admin` (all) and `read-only` (GET).
Default listener: `127.0.0.1:9953`. The server creates a local admin token in
`<data_dir>/control.token` (0640, `api.local_token`), used automatically by the `easydns`
CLI; define `api.tokens` for remote tools and automation.
Errors: `{"error": {"status": 403, "message": "..."}}`. Machine-readable description:
`GET /api/v1/openapi.json`.
| Method | Endpoint | Notes |
|---|---|---|
| GET | `/api/v1/health`, `/healthz`, `/readyz` | public |
| GET | `/api/v1/status` | version, mode, roles, listeners, zone states |
| GET | `/api/v1/stats` | counters, latency quantiles, cache hit rate |
| GET/POST | `/api/v1/zones` | list (`?page&per_page&name&kind`) / create primary zone (`zone_file` or `ns` + `hostmaster`) |
| GET/PUT/DELETE | `/api/v1/zones/{zone}` | details + ETag / replace contents (`zone_file`) / delete API-created zone (409 for config zones) |
| GET/POST | `/api/v1/zones/{zone}/records` | list (`?name&type&page&per_page`) / add `{name,type,ttl,data}` |
| PUT/DELETE | `/api/v1/zones/{zone}/records/{id}` | replace / delete; `If-Match: "<serial>"` → 412 on conflict |
| POST | `/api/v1/zones/{zone}/notify` | send NOTIFY |
| POST | `/api/v1/zones/{zone}/sync` | refresh a secondary now |
| GET | `/api/v1/zones/{zone}/transfers` | transfer history (in/out) |
| GET/DELETE | `/api/v1/cache` | stats / flush (`?domain=`) |
| GET/POST | `/api/v1/upstreams` | status / add upstream (persisted, reload) |
| GET/PUT | `/api/v1/policies` | ACLs, views, rate limit, policy / update allowlist, block action |
| GET/POST | `/api/v1/blocklists` | lists / add a rule |
| POST | `/api/v1/config/reload` | hot reload with rollback |
| GET | `/api/v1/audit` | audit log tail (`?n=`) |
| GET | `/api/v1/query?name=&type=` | resolve through this server |
All state-changing calls are audited (`<data_dir>/audit.log`, JSON lines). Record IDs are
stable hashes of (name, type, data). Changes made via the API persist in the zone files
and in `<data_dir>/api-overlay.yaml`.
```bash
T=$(sudo cat /etc/easydns/data/control.token) # or a token from api.tokens
curl -H "Authorization: Bearer $T" localhost:9953/api/v1/zones
curl -X POST -H "Authorization: Bearer $T" -H 'Content-Type: application/json' \
-d '{"name":"www","type":"A","ttl":300,"data":"192.0.2.10"}' \
localhost:9953/api/v1/zones/example.com/records
```