REST APIAPI overview
API overview
Base URL, the response envelope, the error shape, pagination and status codes shared by every endpoint.
The API is plain JSON over HTTP under /api/v1. Public endpoints return published content without credentials; admin endpoints live under /api/v1/admin and need one of the credentials in Authentication.
BASH
curl -s https://cms.example.com/api/v1/news?locale=en\&limit=3Success envelope
Every successful JSON response wraps its payload in data. List endpoints add metadata with paging information.
JSON
{
"data": [ { "id": "…", "slug": "hello-world", "title": "Hello world" } ],
"metadata": {
"limit": 20,
"offset": 0,
"has_more": true
}
}| Metadata field | Meaning |
|---|---|
limit | Page size used for this response. |
offset | Records skipped (offset-paged lists). |
total | Total matching records, when it is cheap to know. |
has_more | true when another page exists. |
next_cursor | Opaque cursor for cursor-paged lists; pass it back to continue. |
locale | The locale served (content API). |
Errors
Errors use a single shape, so clients can handle them in one place. Always show or log the request_id: it is also sent in the X-Request-ID response header and lets you find the matching server log line.
JSON
{
"code": "unprocessable_entity",
"message": "validation failed",
"request_id": "7c2f4a1e9b3d",
"fields": { "title": "required" }
}| HTTP status | `code` | When |
|---|---|---|
| 400 | bad_request | Malformed JSON, invalid query parameter (for example limit out of range), unknown locale. |
| 401 | unauthorized | Missing, expired or invalid credential. |
| 403 | forbidden | Authenticated but not allowed (role, permission, scope or missing CSRF token). |
| 404 | not_found | Unknown route, record, or a type that is not public. |
| 409 | conflict | Version conflict (someone saved a newer version first) or checkout idempotency_key reused with a different cart. |
| 413 | request_entity_too_large | Body larger than the endpoint accepts (JSON bodies default to 1 MiB). |
| 422 | unprocessable_entity | Validation failed. fields maps field ids to codes such as required, invalid, taken. |
| 429 | too_many_requests | Rate limited. Honour the Retry-After header (seconds). |
| 500 / 503 | internal_server_error / service_unavailable | Server problem. Report the request_id. |
Pagination
limitaccepts 1 to 100. The default is 20 for pages and news and 25 for content types.- Content types use
offset; continue whilemetadata.has_moreistrue. - Always loop on
has_morerather than computing pages fromtotal, which may be absent.
TS
const all = [];
let offset = 0;
for (;;) {
const res = await fetch(`${origin}/api/v1/content/faq?limit=100&offset=${offset}`);
const body = await res.json();
all.push(...body.data);
if (!body.metadata.has_more) break;
offset += body.metadata.limit;
}Conventions
- Field names are
snake_case; timestamps are RFC 3339 strings in UTC. - Ids are opaque strings. Do not parse them.
- Query strings are strict: unsupported parameters on the content API answer
400instead of being ignored. - Browsers on another origin can read published content only if the origin is listed in
security.public_api_origins. Server-side callers are not affected.
The machine-readable contract is the OpenAPI baseline kept in the repository under
docs/api/. CI compares every change to it, so accidental breaking changes are caught before release. Generate a typed SDK with hydro sdk generate.