Read content and media
Create one client for a website API key. The key can read only this website's enabled content and media, so it is safe in browser code when those responses are intended to be public. Core accepts browser reads only from the domain configured for the website in Studio.
import { createNukleClient } from '@lazrus/nukle';
const nukle = createNukleClient({
apiKey: process.env.NUKLE_API_KEY!,
});
Content methods
const modules = await nukle.getModules();
const module = await nukle.getModule('hero');
const hero = await nukle.getSingleton<{ title: string }>('hero');
const cards = await nukle.getRepeatable<{ title: string; body: string }>('cards');
getSingleton returns the first entry's data, or null when the module has
no entries. getRepeatable returns an array of each entry's data in module
order.
Media methods
const files = await nukle.listMedia();
const file = await nukle.getMedia('media-id');
const bytes = await nukle.getMediaFile('media-id');
Media metadata includes the original filename, MIME type, file size, alt text,
and a URL. getMediaFile returns an ArrayBuffer for runtimes that need the
authenticated file bytes.
Treat delivery data as public
The SDK adds the website API-key header for you. Anyone who can inspect your website can use this key to read the same website content and media, so do not store private data in enabled modules or media.