The API
SHADE's content is reachable from any framework, or any program, over HTTP. The Astro site is one client of this API; a Next.js, SvelteKit or Nuxt site, a mobile app or a script uses the same routes.
Version 1
| Path | For | Authentication |
|---|---|---|
/api/v1/content/… | Reading published content: the site, pages, entries, media, redirects, data sources | A read token: Authorization: Bearer <token> (API tokens) |
/api/v1/account/… | Visitors' browsers: signing in, up and out, forms, page views, a user's own data, modules' (the payments module's webhook among them) public and account routes | None (CORS allows the site's origin); a user's session cookie for their own data, their account and modules' account routes |
/api/v1/data/collections/… | Other systems managing collections: list, read, create, update, delete, publish | A data token, which reaches only the collections it was given, read or write |
- What the routes take is described in an OpenAPI 3.1 document at
https://<shade-api>/api/v1/openapi.json, served by every instance without a token. Load it in any OpenAPI tool to browse the routes or generate a client. It includes the public and account routes of the modules that are on, one tag per module (InstalledModule: <name>); account routes are under theaccountSessionscheme (theshade_account.session_tokencookie). Untrusted modules' routes are not in it. Asked with a read token (Authorization: Bearer <token>), it also describes the answers of/api/v1/content/collections/{slug}and/{slug}/{idOrSlug}: the published entry of each collection with a public API that token may read, told apart bycollection. That answer is never kept by a shared cache, and an invalid token gets 401. Without a token the document shows no instance's collections.shade-typeswrites a frontend's types from it (Collections). - v1 is a promise: a breaking change comes as
/api/v2, next to v1. Adding routes or optional fields is not breaking. - The admin's own API (
/api/…, unversioned, for the admin only) keeps one verb per kind of change:PUTsends the whole thing (a webhook, a role, an on/off switch:{ enabled }, a capability's{ on }),PATCHonly the parts that change (the site settings, a team member, retention periods, alert rules). A step confirmed by typing a name sends it asconfirm(installing or removing an untrusted module, turning off, uninstalling, approving). - Previews are
GET /api/v1/content/preview?token=…(C14): what a preview link of another frontend shows. Thetokenis the one in the link the frontend's preview route was opened with; the site asks with its read token (client.contentPreview(token)). It answers{ kind: 'entry', locale, entry }(an entry's version, a draft too, as a published entry:publishedAtis the version's time) or{ kind: 'set', locale, name, entries, removed }(a module's set of versions, such as an editorial release, as it will publish them, and{ collection, id }of what it unpublishes), never cached. 401 when the link expired or was revoked, or its maker may no longer read it; 404 when what it shows is gone. The admin makes the links:POST /api/collections/:slug/:id/previewand a module's own route for a set (the editorial module's releases) with{ frontendId?, locale?, versionId?, shareHours? }(signed in, never with a token). - Search is
GET /api/v1/content/search?q=&lang=&collections=&limit=&cursor=: full-text search over published entries of collections with a public API (Search).qis up to 200 characters (quotes,orand-wordwork);langone of the site's visible languages;collectionsslugs, comma separated;limitup to 50;cursorthenextof the page before. It answers{ items, next }, each item withcollection,id,slug,titleandhighlights: [{ field, text, ranges }], the text around the match as plain text with the matched[start, end)ranges, never HTML. It is rate limited per token (429), refuses a search that takes more than 3 seconds (503), and answers 404 while an admin has Search switched off. - The TypeScript client
@shadestack/core/sdk(createShadeClient) uses v1, withsearch(query, options). It is plainfetchand works in any framework. Given the typesshade-typeswrites (createShadeClient<ShadeCollections>(…)),collection(slug)knows each collection's data. It knows no module: a module's read model isread<T>(path, query); a site's pages are@shadestack/client/render'screateSiteClient. A request that takes longer thantimeoutMs(10 seconds by default) fails with aTimeoutError;signalaborts every request still running. - Errors are JSON:
{ "error": { "code", "message", "key"?, "params"?, "issues"? } }withVALIDATION(422),UNAUTHORIZED(401),FORBIDDEN(403),NOT_FOUND(404),CONFLICT(409) orRATE_LIMITED(429), and from the server's sideUNAVAILABLE(503: starting up, maintenance mode, Redis down, too busy, or an outside service it needs failing; try again afterRetry-After) orINTERNAL(500: a failure SHADE did not expect, recorded in its error log). The OpenAPI document describes the 4xx, 500 and 503 answers of every route. - The admin screens' own API (
/api/…withoutpublicorvisitor) is not part of the contract. - Every instance serves
/.well-known/security.txt(RFC 9116): where to report a security hole in it (SHADE_SECURITY_CONTACT; empty, SHADE's maintainers' address), in Dutch or English.
Examples
Every route is in the API reference. With a read token, from any shell:
TOKEN=shd_… # a read token, from the admin's API tokens screen
curl -H "Authorization: Bearer $TOKEN" https://admin.example.com/api/v1/content/site
curl -H "Authorization: Bearer $TOKEN" \
"https://admin.example.com/api/v1/content/collections/<collection>?perPage=10&locale=en"
With a data token that may write a collection, another system creates an entry, then publishes it:
curl -X POST -H "Authorization: Bearer $DATA_TOKEN" -H "Content-Type: application/json" \
-d '{"data":{"title":"Opening hours changed","slug":"opening-hours-changed"},"note":"From the booking system"}' \
https://admin.example.com/api/v1/data/collections/website-posts
curl -X POST -H "Authorization: Bearer $DATA_TOKEN" -H "Content-Type: application/json" -d '{}' \
https://admin.example.com/api/v1/data/collections/website-posts/<id>/publish
A refusal is JSON with a code: { "error": { "code": "VALIDATION", "message": "…", "issues": [ … ] } }.
Checking a webhook's signature
SHADE signs every webhook it sends with the Standard Webhooks scheme: the headers
webhook-id, webhook-timestamp (seconds) and webhook-signature (v1, and a base64 HMAC-SHA256 of
<id>.<timestamp>.<body>), keyed with the address's secret (whsec_…, shown once when the address is added). The
Standard Webhooks libraries check it in one call; without one, in Node:
import { createHmac, timingSafeEqual } from 'node:crypto'
/** True when the raw body came from SHADE, signed less than five minutes ago. */
export function fromShade(secret: string, headers: Headers, rawBody: string): boolean {
const id = headers.get('webhook-id')
const timestamp = headers.get('webhook-timestamp')
const signatures = headers.get('webhook-signature')
if (!id || !timestamp || !signatures) return false
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false
const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64')
const expected = createHmac('sha256', key).update(`${id}.${timestamp}.${rawBody}`).digest()
return signatures.split(' ').some((signature) => {
const [version, value = ''] = signature.split(',')
const given = Buffer.from(value, 'base64')
return version === 'v1' && given.length === expected.length && timingSafeEqual(given, expected)
})
}
Check the body exactly as it arrived, before parsing it. webhook-id is the same on every try of one message, so a
receiver that stores the ids it handled answers a retry without doing the work twice.
Rendering pages in another framework
The website module's pages are trees of elements (PublishedPage.tree), which
@shadestack/render resolves for every framework (Frameworks).
GET /api/v1/content/website/theme.css: the theme as CSS variables (--color-primary, spacing, fonts) with the web fonts'@font-facerules, the same CSS the Astro site puts in its pages; a read model of the website module, under its prefix (below). The site's styles (styles.css, as the last publish compiled them) use these variables as their defaults and leave them out, so a site writes them once.- Code: the website module's read routes (
server/read.ts).
How the document is made
Each route in apps/api/src/routes/content.ts and routes/user.ts carries a description next to
it, from the same Zod schemas its controller parses with:
group.get('/media', doc({ summary: 'Media items by id, with their sizes and alt text', query: read.MediaIds }), read.media)
doc({ summary, description?, query?, body?, bodyType?, auth? })(apps/api/src/http/router.ts) is not run as middleware; a group made withroutes(app, { document })records the route.apps/api/src/http/openapi.tsturns the recorded routes into the document. Zod's ownz.toJSONSchema(input side) gives the schemas, so there is no extra dependency and a route cannot drift from its description.- Responses are described in words for now; their shapes are the types in
@shadestack/core/schema, and the website module's pages' in@shadestack/render(PublishedPage,PublishedLayout,PublishedTheme). The collection reads are the exception, for a read token only:withCollectionsadds each public collection's published entry (publicCollectionSchemas, frompublishedDataSchema); tests inapps/api/test/http/openapi.collections.test.ts. - Modules' read models are described at the address they are served at, under their module's prefix:
the website module's
/pagesas/api/v1/content/website/pages. Core adds the prefix from the module's name for every module and knows none of their paths; a path without a module's prefix is 404. Tests:apps/api/test/http/controllers/content.module-read.test.ts. - Tests:
apps/api/test/http/openapi.versioned.test.tschecks the document (paths, path and query parameters, bodies, authentication), that v1 answers and that the unversioned/api/publicand/api/visitorand the old/api/v1/publicand/api/v1/visitorare 404.
Details
- Site settings in code:
SiteSettingsinshade/features/settings/shared/settings.ts; the site's name, URL and languages are read withcontent.readatGET /api/settings/public; over MCPsettings.readandsettings.updateare in theadminclass, which the AI never holds. The admin form sends only the top-level sections that changed; saving is a partial update (PATCH): only the sections sent change,defaultSeois merged one level deep, then the whole result is validated again; fields not sent are never reset; the route hands the body to the service as sent (rawBody), so the partial schema fills in no defaults for what was not sent. Time zone must be an IANA name the server knows, else VALIDATION "Unknown time zone"; changing the default language once any collection has an entry is CONFLICT. Per-language name and default SEO live intranslations. A stored settings row from before multi-language (a singlelocale) is read as that default language. The public site data leaves outdefaultSeo(PublishedSettings); the defaults are applied on the server when a page is resolved. A settings change requests a rebuild of the frontends after the save commits. On the site the site name isog:site_name, the site URL is used for canonical URLs,hreflanglinks and the sitemap, and<title>is the title template.