This guide adds Lynkow to a site you already have, with the Next.js App Router. To start a new site instead, follow the Quick Start.
Reference - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
SDK: SDK Reference and
ContentsServiceAPI: Storefront: Content
Prerequisites
Node.js 20.9 or later (the SDK alone runs on Node 18)
A Lynkow site, and its Site ID: the admin shows it under Settings > Developers > Storefront
Install
npm install lynkowIf you work with an AI coding assistant, also install the Lynkow AI skills from the project root. Install the Lynkow AI Skills explains the formats.
npx @lynkow/skills@latestCreate the client
Add your Site ID to .env.local:
NEXT_PUBLIC_LYNKOW_SITE_ID=your-site-idCreate one shared client in lib/lynkow.ts and import it everywhere:
import { createClient } from 'lynkow'
export const lynkow = createClient({
siteId: process.env.NEXT_PUBLIC_LYNKOW_SITE_ID!,
publishableKey: process.env.NEXT_PUBLIC_LYNKOW_PUBLISHABLE_KEY,
fetchOptions: { next: { revalidate: 60 } },
})Option | Default | Use |
|---|---|---|
| required | Your Site ID. |
| none | The site's storefront key ( |
| the site's default locale | Locale of every request. See Multi-language. |
|
| Merged into every |
|
| Retries reads on 429, 503 and network errors. |
The SDK Reference lists the other options. Never set serverKey or clientIp on this shared client: a call made for one buyer from your server needs its own client (Server Key and Buyer IP). To refresh pages as soon as content changes, add a webhook: see Webhooks & Cache Revalidation.
List articles
app/blog/page.tsx:
import { lynkow } from '@/lib/lynkow'
export default async function BlogPage() {
const { data: articles, meta } = await lynkow.contents.list({
limit: 10,
sort: 'published_at',
order: 'desc',
})
return (
<main>
<h1>Blog</h1>
<ul>
{articles.map((article) => (
<li key={article.id}>
<a href={`/blog/${article.slug}`}>{article.title}</a>
{article.excerpt && <p>{article.excerpt}</p>}
</li>
))}
</ul>
<p>Page {meta.currentPage} of {meta.lastPage}</p>
</main>
)
}List rows carry no body. Read the article itself for it.
Show one article
app/blog/[slug]/page.tsx:
import { notFound } from 'next/navigation'
import { isLynkowError } from 'lynkow'
import { lynkow } from '@/lib/lynkow'
export default async function ArticlePage({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params
let article
try {
article = await lynkow.contents.getBySlug(slug)
} catch (error) {
if (isLynkowError(error) && error.code === 'NOT_FOUND') notFound()
throw error
}
return (
<article>
<h1>{article.title}</h1>
{article.author && <p>By {article.author.fullName}</p>}
<div dangerouslySetInnerHTML={{ __html: article.body }} />
</article>
)
}body is rendered HTML. The article also carries its categories, tags and SEO fields: see the SDK Types. Error Handling & Resilience covers the other error codes.
Next Steps
Complete Integration Checklist - every feature, with its guide
Build a Blog with Next.js - categories, pagination, metadata and images
Media & Image Optimization - responsive image variants