Content API

Your whole site in one request.

Leiho serves your content to the front end, already shaped for it. WordPress stays the single source of truth, and your repository holds code, not content.

build
import { loadLeihoContent, indexLeihoContent } from 'leiho/content';

const { data } = await loadLeihoContent({ url: 'https://cms.example.com' });
const content = indexLeihoContent(data);

const home = content.byPath('/');
home.fields.hero_title;
304 Not Modified · GET /wp-json/leiho/v1/export
01

One request per build

The export returns every published item at once, instead of one request per page.

02

304 when nothing changed

Responses carry an ETag. An unchanged build gets a 304 and downloads nothing.

03

Generated types

npx leiho types writes TypeScript declarations of exactly the JSON you receive.

04

Snapshot fallback

If WordPress doesn't answer, the build carries on with the last known content and says so.

05

Front-end shapes

Images come with url, alt, sizes; relations with their path; rich text already rendered.

06

Plugs into your caches

Object cache, page caches and CDNs are used and purged when content changes.

Load once, read everywhere

One call in your build, then look pages up by path, type or slug.

build
import { loadLeihoContent, indexLeihoContent } from 'leiho/content';

const { data } = await loadLeihoContent({ url: 'https://cms.example.com' });
const content = indexLeihoContent(data);

const home = content.byPath('/');
home.fields.hero_title;

Endpoints

GET /wp-json/leiho/v1/export returns everything. /content filters and paginates, /content/{id} returns one item (drafts for logged-in editors), /types returns the TypeScript declarations.

Public or restricted

Published content is public by default. Switch the API to restricted and set LEIHO_TOKEN in your build environment.

Edit the real site.

Free and open source. Try it on a real WordPress, in your browser.