Appearance
OpenAPI specification
The whole API, as one machine-readable document:
https://docs.flatnode.net/openapi.yaml
It is OpenAPI 3.1, and it describes every route under https://admin.flatnode.net/api/v1: each path, method, request body, query parameter, response shape and error, with the token abilities each operation needs. It is what to hand a client generator, an API explorer, or an agent that is going to drive the API.
Reading it
A few conventions, so the document reads the way the prose pages do:
x-abilitieson every operation lists the token abilities that satisfy it, in both spellings:["document.read", "read"]means a token holding either one may call it. See Token Abilities.- Every identifier is a uuid, typed
format: uuid, in paths and in bodies alike. The one numeric exception,owner_id, is marked as such where it appears. PUTis an alias ofPATCHon the four resources Laravel registers both for (document,library,component,content). The operations are listed twice so a generator sees both; they take the same body and answer the same way.- The envelope. Most responses are
{message, data}, with apagerbeside them on a paged listing. The three reads that answer a rendered tree -GET /document/{uuid},GET /document/by-slug/{slug}andGET /content/{uuid}- and the two that answer a bare resource -PATCH /document/{uuid}andGET /tree/{uuid}- are spelled out individually. - A component's schema is JSON Schema. The
JsonSchematype in the document is deliberately open; what it may contain is the closed vocabulary in Components, and the meta-schema that enforces it is served athttps://admin.flatnode.net/component.schema.json.
Generating a client
Any OpenAPI 3.1 generator works. For a TypeScript consumer, openapi-typescript and its fetch wrapper need no build step:
bash
npx openapi-typescript https://docs.flatnode.net/openapi.yaml -o flatnode.d.tsts
import createClient from "openapi-fetch";
import type { paths } from "./flatnode";
const api = createClient<paths>({
baseUrl: "https://admin.flatnode.net/api/v1",
headers: { Authorization: `Bearer ${process.env.FLATNODE_TOKEN}` },
});
const { data } = await api.GET("/document/by-slug/{slug}", {
params: { path: { slug: "home" }, query: { locale: "en" } },
});Keeping it true
The document is maintained by hand, next to the code, and a test fails the build when it drifts: every route has to be described, every described operation has to be a route, the abilities on each have to be the ones the route enforces, and the fields of each resource have to be the ones the API declares. What it cannot catch is a wrong description of a value, so if a response disagrees with the document, the response is right and the document has a bug - please say so.