Docs›Integrations›Next.js

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

  1. In Integrations, choose Next.js. Copy the API key it makes (it starts wsk_) into your project as WRITING_STUDIO_KEY.
  2. Add the starter files shown there: lib/writing-studio.ts, the blog and post pages, and app/api/revalidate/route.ts.
  3. 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 as If-None-Match and an unchanged answer is a 304 with no body.
  • Cache-Control: private, max-age=60.
  • 120 requests a minute per key. Every answer has X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset; past the limit you get 429 with Retry-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.