Get a post
A published post by slug, with the body in HTML and in Markdown.
GET/public/v1/sites/{siteId}/posts/:slug
GET/public/v1/posts/:slug
The first is the per-site route (secret key only, kept at the edge for up to a day and purged when the post changes); the second is the key route (secret or publishable). See Two routes.
Parameters
| Parameter | Default | Description |
|---|---|---|
slugpathrequired | — | Slug of the post version, as it appears in the list. |
localestring | — | Language of the version. Without it, a slug that exists in more than one language resolves to the site's main language. |
Response
The same fields as an item of the list, inside data, plus:
bodyHtml: the rendered body. Raw HTML coming from the Markdown is escaped andjavascript:links are dropped, so it is safe to inject straight into the page.bodyMarkdown: the body in Markdown. The title is not in the body (it comes intitle).
{
"data": {
"id": "7c0e…",
"locale": "en-US",
"slug": "managing-many-blogs",
"title": "Managing many blogs",
"bodyHtml": "<p>…</p>",
"bodyMarkdown": "…",
"…": "the other fields from the list"
}
}A slug that does not exist, is not published or belongs to another site answers 404 NOT_FOUND.
Old slug: 301
When someone changes the slug of a published version in the panel, the previous slug keeps pointing to it. Requesting the old slug answers 301 Moved Permanently:
HTTP/1.1 301 Moved Permanently
Location: new-slug?locale=en-US
Cache-Control: private, no-cache
{ "redirectTo": { "slug": "new-slug", "locale": "en-US" } }Locationis relative to the endpoint itself (/public/v1/posts/new-slug?locale=en-US).- All old slugs of a version point straight to the current one, with no redirect chain.
- Going back to an old slug makes it valid again; the one that was left starts redirecting.
- The old slug stays reserved: another post of the same site and language cannot use it. Another language or another site can.
- Without
?locale=, a current slug in any language wins over an old slug. - If the version goes offline (unpublished or deleted), the old slug answers
404. Deleting the post frees its old slugs. - Versions that were never published keep no old slug: nobody had the link.
fetch follows the 301 on its own (Authorization goes along, because the destination is the same origin) and returns the post with the current slug. So the blog only needs to compare: if data.slug differs from the slug in the URL, send the visitor (and Google) to the new URL with a permanent redirect, as in the Next.js example. Those who prefer not to follow it can use redirect: "manual" on the server and read redirectTo from the body.
Examples
curl -L -H "Authorization: Bearer $POSTREAM_API_KEY" \
"https://api.postream.blog/public/v1/sites/$POSTREAM_SITE_ID/posts/managing-many-blogs?locale=en-US"const res = await fetch(`https://api.postream.blog/public/v1/sites/${process.env.POSTREAM_SITE_ID}/posts/${encodeURIComponent(slug)}?locale=en-US`, {
headers: { Authorization: `Bearer ${process.env.POSTREAM_API_KEY}` },
});
if (res.status === 404) return null;
const { data: post } = await res.json();import { notFound, permanentRedirect } from "next/navigation";
import { getPost } from "@/lib/postream";
export default async function BlogPost({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
const post = await getPost(slug, "en-US");
if (!post) notFound();
if (post.slug !== slug) permanentRedirect(`/blog/${post.slug}`);
return <article dangerouslySetInnerHTML={{ __html: post.bodyHtml }} />;
}