Configure a Next.js site and add a server-only helper to read published articles.
Use a TypeScript Next.js App Router project. The examples place app/ and lib/ at the project root. If your project uses src/, place both folders inside it. Keep these values on the website server.
POSTPARTICLE_URL=https://cms.example.com
POSTPARTICLE_PROJECT=demo
POSTPARTICLE_ORGANIZATION_ID=<organization-uuid>
WEBSITE_URL=https://journal.example.com
Set POSTPARTICLE_URL to the base URL of your Postparticle deployment, POSTPARTICLE_PROJECT to your project ID, POSTPARTICLE_ORGANIZATION_ID to the organization that owns that project, and WEBSITE_URLto the base URL readers use for your public website, without a trailing slash. Replace the example values. Configure these variables in each Vercel environment, or in your hosting provider’s environment settings. Restart the local server after changing .env.local.
npm install server-only react-markdown remark-gfmThe public articles API needs no Spaces credentials, access tokens, or login cookies. It does not expose drafts or management endpoints.
If you use an AI coding assistant, provide the values below and ask it to inspect your repository before editing. The prompt directs it to follow your framework and project conventions, keep API requests on the server, and use the public endpoints described in these guides.
Replace the three placeholders before copying. Do not include credentials; the published-content API does not require them.
Integrate Postparticle into this existing website.
Postparticle base URL: {{POSTPARTICLE_URL}}
Postparticle project ID: {{POSTPARTICLE_PROJECT}}
Postparticle organization UUID: {{POSTPARTICLE_ORGANIZATION_ID}}
Public website URL: {{WEBSITE_URL}}
Before changing files:
1. Inspect the repository structure, framework and version, package scripts, existing content/data access, routing, styling, and metadata conventions.
2. Identify the smallest integration that fits those conventions. Do not replace the app structure or redesign unrelated pages.
3. Check the current Postparticle developer guides or integration reference for the verified public API contract. Do not invent endpoints, fields, or an SDK.
Implementation requirements:
- Read published content from the public Postparticle API on the website server. Never put credentials, private storage keys, or server configuration in browser code. The public content API does not require workspace credentials.
- Use the existing server-rendering or server-side data-fetching pattern. Encode project IDs, slugs, and document keys as URL path segments, and encode query parameters with URLSearchParams or the framework's equivalent.
- Use these endpoints when needed: GET {{POSTPARTICLE_URL}}/api/v1/projects/{{POSTPARTICLE_PROJECT}}/articles?organizationId={{POSTPARTICLE_ORGANIZATION_ID}} for full article listings, GET {{POSTPARTICLE_URL}}/api/v1/projects/{{POSTPARTICLE_PROJECT}}/articles/metadata?organizationId={{POSTPARTICLE_ORGANIZATION_ID}}&page=1&pageSize=12&order=desc for body-free listing metadata, GET {{POSTPARTICLE_URL}}/api/v1/projects/{{POSTPARTICLE_PROJECT}}/articles/{slug}?organizationId={{POSTPARTICLE_ORGANIZATION_ID}}, and GET {{POSTPARTICLE_URL}}/api/v1/projects/{{POSTPARTICLE_PROJECT}}/documents/{key}?organizationId={{POSTPARTICLE_ORGANIZATION_ID}}.
- The API returns published content only. Handle 404 for missing or unpublished content, 400 for invalid input, 503 for service or storage failures, and network errors using the project's existing error and not-found conventions.
- Preserve the existing site's caching policy where possible. The article metadata endpoint is edge-cached for 45 seconds with up to 15 seconds of stale-while-revalidate; other API responses are no-store. The website may add its own cache, so document the combined freshness tradeoff.
- If rendering article Markdown, use the project's established safe Markdown renderer. Keep raw HTML disabled unless the project has a deliberate, reviewed sanitization policy. Use resolved media URLs from the public response.
- Where the project supports article metadata, use the article SEO title and description with title and excerpt fallbacks, and use the canonical public website URL based on {{WEBSITE_URL}}.
- Follow the repository's language, lint, formatting, accessibility, and testing conventions. Add only dependencies that are necessary and not already available.
Make the integration, then report which files changed, the API behavior used, the cache policy, and any setup values the site owner must configure. Do not expose secrets or claim that a command passed unless you ran it.Create lib/content.ts in your website. The helper defines the article response shape, encodes project IDs and slugs, omits unset query parameters, and sets a 60-second revalidation interval. connection() defers the fetch until a request arrives, so the production build does not require a running Postparticle instance.
import "server-only";
import { notFound } from "next/navigation";
import { connection } from "next/server";
export interface PublicArticle {
title: string;
slug: string;
excerpt: string;
body: string;
author: string;
tags: string[];
articleDate: string;
seoTitle: string;
seoDescription: string;
createdAt: string;
updatedAt: string;
publishedAt: string;
coverUrl: string | null;
socialImageUrl: string | null;
}
export interface ArticlePage {
items: PublicArticle[];
total: number;
page: number;
pageSize: number;
}
interface ArticleQuery {
q?: string;
tag?: string;
order?: "asc" | "desc";
page?: number;
pageSize?: number;
}
export const websiteUrl = process.env.WEBSITE_URL || "http://localhost:3001";
const cmsUrl = process.env.POSTPARTICLE_URL || "http://localhost:3000";
const project = process.env.POSTPARTICLE_PROJECT || "demo";
class ContentError extends Error {
constructor(public status: number) {
super(`Postparticle returned ${status}`);
}
}
async function get<T>(path: string): Promise<T> {
// Fetch at request time so a build does not depend on a running CMS.
await connection();
const organizationId = process.env.POSTPARTICLE_ORGANIZATION_ID;
if (!organizationId)
throw new Error("POSTPARTICLE_ORGANIZATION_ID must be configured.");
const url = new URL(
`/api/v1/projects/${encodeURIComponent(project)}/${path}`,
cmsUrl,
);
url.searchParams.set("organizationId", organizationId);
const response = await fetch(url, { next: { revalidate: 60 } });
if (!response.ok) throw new ContentError(response.status);
return response.json() as Promise<T>;
}
export function getArticles(query: ArticleQuery = {}) {
const params = new URLSearchParams();
for (const [key, value] of Object.entries(query)) {
if (value !== undefined && value !== "") params.set(key, String(value));
}
return get<ArticlePage>(`articles?${params}`);
}
export async function getArticle(slug: string) {
try {
return await get<PublicArticle>(`articles/${encodeURIComponent(slug)}`);
} catch (error) {
if (error instanceof ContentError && error.status === 404) notFound();
throw error;
}
}
The helper maps an article 404 response to Next.js notFound(). Other HTTP errors and network failures propagate to the website’s error boundary. The TypeScript response types describe the API contract; they do not validate responses at runtime.
These files provide the styles used by the later examples. In an existing website, merge the metadata into your layout and keep your current design.
import type { Metadata } from "next";
import Link from "next/link";
import { websiteUrl } from "../lib/content";
import styles from "./blog.module.css";
export const metadata: Metadata = {
title: { default: "Demo Journal", template: "%s · Demo Journal" },
description:
"A sample website that renders published articles from Postparticle.",
metadataBase: new URL(websiteUrl),
};
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body className={styles.body}>
<header className={styles.header}>
<Link href="/">Demo Journal</Link>
<Link href="/blog">Articles</Link>
</header>
<main className={styles.main}>{children}</main>
</body>
</html>
);
}
.body {
margin: 0;
color: #203048;
background: #f9f9f6;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
.body a {
transition: filter 140ms ease;
}
@media (hover: hover) {
.body a:hover {
filter: brightness(0.92);
}
}
.body * {
box-sizing: border-box;
}
.body small {
font-size: 13px;
}
.header {
max-width: 1120px;
margin: auto;
padding: 30px 28px;
display: flex;
justify-content: space-between;
border-bottom: 1px solid #dfe4eb;
}
.header a {
text-decoration: none;
font-size: 16px;
font-weight: 600;
}
.main {
max-width: 1120px;
padding: 60px 28px;
margin: auto;
}
.main h1 {
font:
64px/1.15 Georgia,
serif;
letter-spacing: -2px;
margin: 20px 0 30px;
}
.main a {
color: #275ac0;
}
.eyebrow {
font-size: 13px;
letter-spacing: 0.8px;
}
.intro {
max-width: 450px;
line-height: 1.8;
color: #68758b;
margin-bottom: 60px;
}
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 25px;
margin: 25px 0 50px;
}
.cards article {
border: 1px solid #dfe4eb;
border-radius: 8px;
background: #fff;
padding: 25px;
}
.cards h2,
.cards h3 {
font:
25px/1.3 Georgia,
serif;
}
.cards p {
font-size: 16px;
line-height: 1.8;
color: #68758b;
}
.cards time {
font-size: 13px;
color: #68758b;
}
.cards img {
width: 100%;
border-radius: 5px;
}
.cards a {
text-decoration: none;
}
.article {
max-width: 760px;
margin: auto;
line-height: 1.9;
}
.article img {
max-width: 100%;
border-radius: 5px;
}
.article pre {
overflow-x: auto;
padding: 15px;
background: #edf0f4;
font-size: 13px;
}
.meta {
color: #68758b;
font-size: 13px;
margin-bottom: 35px;
}
.tag {
display: inline-block;
font-size: 13px;
background: #eaf0fb;
border-radius: 4px;
padding: 4px 8px;
margin: 5px 5px 5px 0;
}
.form {
display: flex;
gap: 15px;
align-items: flex-end;
flex-wrap: wrap;
margin: 30px 0;
}
.form label {
display: grid;
gap: 8px;
font-size: 14px;
}
.form input,
.form select {
padding: 10px;
border: 1px solid #dfe4eb;
border-radius: 5px;
font-size: 14px;
}
.form button {
padding: 11px 20px;
background: #275ac0;
border: none;
border-radius: 5px;
color: white;
font-size: 14px;
transition: filter 140ms ease;
}
.form button:not(:disabled):hover {
filter: brightness(0.92);
}
.main table {
border-collapse: collapse;
}
.main td,
.main th {
padding: 8px;
border: 1px solid #dfe4eb;
}
@media (max-width: 700px) {
.cards {
grid-template-columns: 1fr;
}
.main h1 {
font-size: 45px;
}
.main {
padding-top: 40px;
}
}
.error {
color: #94323a;
background: #fff0f1;
border: 1px solid #e6b5ba;
border-radius: 8px;
padding: 18px 22px;
margin: 24px 0;
}
The files are in examples/next-blog. Start Postparticle locally and publish an article, then run this command from the repository root:
POSTPARTICLE_URL=http://localhost:3300 POSTPARTICLE_PROJECT=demo POSTPARTICLE_ORGANIZATION_ID="<organization-uuid>" WEBSITE_URL=http://localhost:3301 npm run example:dev -- --port 3301Open the local example blog. Run npm run example:build to build it. To deploy the example as a separate website, copy its files and install its dependencies in that project. Do not copy Postparticle storage configuration.
See the integration reference for the optional typed client and JSON document endpoint. This application does not publish an SDK package.