Quickstart
A blog index, a rendered post with SEO, and a draft you create, preview, and publish.
Install
Read: list, fetch, render, describe
import { createClient } from "@floggy/cms";
// No key needed for published, public content.
const floggy = createClient({ project: "projecta" });
// Blog index
const { posts, pageInfo } = await floggy.posts.list({ page: 1, perPage: 10 });
for (const post of posts) {
console.log(post.title, "/" + post.slug);
}
console.log(`page ${pageInfo.page}, hasMore: ${pageInfo.hasMore}`);
// One post, rendered to HTML, with SEO ready to drop in
const post = await floggy.posts.get("hello-world", { format: "html" });
console.log(post.rendered); // ready-to-inject HTML string
const metadata = floggy.seo.meta(post); // Next.js-compatible Metadata object
Write: draft, preview, publish
Writes need an flg_ key. Keep it server-side.
import { createClient } from "@floggy/cms";
// posts:write to create and publish, posts:read to preview the draft.
const floggy = createClient({
project: "projecta",
key: process.env.FLOGGY_API_KEY,
});
// 1. Create a draft. `content` is Markdown, `slug` comes from the title,
// and nothing is live yet.
const { id } = await floggy.posts.create({
title: "Launch Day",
excerpt: "We shipped.",
content: "## What changed\n\nWe shipped the new **editor**.",
});
// 2. Read it back by slug before anyone else can. Published posts and
// unknown slugs both return null here.
const draft = await floggy.posts.draft("launch-day");
console.log(draft?.rendered);
// 3. Ship it.
await floggy.posts.publish(id);
Authenticated calls act on the key owner's blog, not on project. project only selects which blog the public reads come from.
Next steps
- Build a real page (
generateMetadata, JSON-LD, feeds, a/drafts/[slug]preview route): SDK reference - Creating a key and picking its scopes: Authentication
- The REST endpoints underneath, for curl and non-SDK use: API reference
- Revalidate your frontend on publish: Webhooks