hatchmark serve answers a read-only JSON API beside the pages: the dashboards of the last good
build, and each block’s numbers in any state a reader can reach on the page, as a block payload
your app can draw or read. It needs no setting: the API is on whenever serve runs. To show the
blocks as the pages draw them, use the chart elements or React components (Embedding).
Surfaces
The same routes answer under two prefixes./api/v1 shows what the pages show, to the same people, so it sits behind the same access control
(who can see the dashboards). /embed/v1
and the paths under it refuse every request without a valid token, so you can exempt exactly those
from a sign-in proxy as you would /mcp, with a rule that stops at the version, such as
^/embed/v1(/|$). Other paths under /embed/ are ordinary pages. A token can read every route; never put one in a browser.
Routes
Every route is a GET (HEAD works too) and answers JSON, excepttypes.d.ts, which answers TypeScript.
Dashboard
filters.period,filters.grainandfilters.segments: the filter, its options and the value the page shows first.filters.selects: each select filter’sid,label,multiple,selectedand every value inoptions, withlisted: truewhen the filter lists its options and offers no “All”.filters.picks: the categories a reader can pick in a block to filter the others:id,label, theblocksthat offer the pick and itsoptions.blocks: each block’sid,kind,heading(title,subtitle),span,heightandidFromPosition. A block withoutid:in its YAML gets one from its position, such astable_3, which changes when blocks move; setid:on blocks an app reads.
Filters
Block and draw routes take the page URL’s filter parameters, checked the same way ashatchmark render --filter (Render to PNG or PDF). Filters you leave out take the
dashboard’s defaults.
The API answers every state the page can show: each period preset, custom range, segment and select
combination and pick the build reached. A state the page can’t reach gets
HM6008.
Custom ranges and sets of several select values are computed on request from what the build
embeds, as the page does in the browser. serve computes one at a time; up to 8 more wait their
turn for at most 10 seconds each, and past either limit the request gets HM6007 with
Retry-After: 5. Presets and single values never wait.
Block payload
A block payload (hatchmark.block/1) is one block’s render model with everything its renderer
reads. Its JSON Schema ships in the package as schema/block-1.schema.json.
- A number is a number, or
nullwhen it is undefined; the page shows that as an em dash. An empty window is a reason such as"no_data", never 0. block.picklists thekeysa reader can pick in the block, in the order it draws them, with the pick filter’sidandlabel; a key isnullwhere picking it would not apply.state.clearednames a requested pick that the other filters leave with no rows: the payload shows the block without it, as the page drops it.- Payloads are the same for the same state of the same build, except
freshness. - Within
block/1, fields and block kinds are only added. Ignore fields you don’t know. - A dashboard on which no block reads data, such as a page of text notes, has no as-of date, so
its blocks have no payload: the block route answers 404, and
types.d.tsleaves them out. Its draw routes still answer.
Draw lists
Thedraw routes of a block and of the whole dashboard lay the payload out at one width for
clients that paint primitives instead of running the renderer, such as a native app. The layout
is in the path, so every query parameter stays a filter:
For example,
/api/v1/dashboards/sales/draw/phone/390?period=last_90_days.
KPIs, line, area and bar charts, tables and text have draw lists; other kinds return 400 on the
block route and status: "unsupported" in the dashboard’s list.
Caching
Every answer carries a strongETag and Cache-Control: private, no-cache: clients revalidate
with If-None-Match and get 304 while the build and the state are the same. Shared caches don’t
store answers, because each one is for a viewer behind your gateway or a token holder.
Calling from another origin
An app on the same origin as serve, such asacme.com/bi/ routed to serve by your gateway, needs no
setting: the browser sends the gateway’s cookie.
An app on another origin of the same site, such as app.acme.com calling bi.acme.com, needs the
gateway’s cookie to cover both hostnames (a cookie domain of .acme.com) and the app’s origin in
HATCHMARK_ALLOWED_ORIGINS:
/api/v1 answers with the viewer’s cookies. List origins as scheme,
host and port, separated by commas, with no path. Unset, the API answers same-origin only. Requests
are plain GETs with no custom headers, so browsers send no preflight. /embed/v1 answers any origin
but never reads cookies.
Checks
Errors answer a diagnostic report, the JSONcheck --json prints, with an HTTP status.