Next.js and the content API
Serve Writing Studio posts from the content API on your Next.js site, live without a rebuild.
New to Writing Studio? See what it does for your Next.js blog.Your site reads its posts from Writing Studio, and Writing Studio tells your site when a new one is live so it updates without a rebuild.
Set up
- In Integrations, choose Next.js. Copy the API key it makes (it starts
wsk_) into your project asWRITING_STUDIO_KEY. - Add the starter files shown there:
lib/writing-studio.ts, the blog and post pages, andapp/api/revalidate/route.ts. - Enter your site address, the blog path (default
/blog) and the revalidate URL, then connect.
API reference
Every request sends Authorization: Bearer wsk_…. Call it from your server, never from the browser (it has no CORS headers, so the key stays private).
GET /api/v1/posts?limit=20&offset=0
Your published posts, newest first, without their HTML.
{ "posts": [{ "slug": "…", "title": "…", "excerpt": "…", "metaTitle": "…", "metaDescription": "…",
"image": { "url": "…", "alt": "…" }, "author": "…", "path": "/blog/…", "publishedAt": "…", "updatedAt": "…",
"wordCount": 2400, "faq": [{ "q": "…", "a": "…" }] }], "total": 12, "limit": 20, "offset": 0 }
limit is 1 to 100.
GET /api/v1/posts/<slug>
One post, with html (the article, then its FAQ). 404 if there's no published post at that slug.
Caching and limits
- Answers carry an
ETag. Send it back asIf-None-Matchand an unchanged answer is a304with no body. Cache-Control: private, max-age=60.- 120 requests a minute per key. Every answer has
X-RateLimit-Limit,X-RateLimit-RemainingandX-RateLimit-Reset; past the limit you get429withRetry-After. The starter caches pages for an hour, so you'll rarely get near it.
The revalidate call
When a post goes live, Writing Studio POSTs to your revalidate URL:
{ "event": "post.published", "slug": "…", "paths": ["/blog", "/blog/…"], "sentAt": "…" }
signed with your API key in X-WritingStudio-Signature (see signatures). The starter's route checks it and revalidates the paths.
Can’t find what you need? Email us.