Get started

Public content API

The public API serves published content anonymously, so any website or app can display it without an API key. It is read-only and shows only what you explicitly make public.

What is public

A record is returned only when all of these are true:

  1. Its entity has Allow anonymous read access enabled (entity settings → Public API).
  2. If the entity has a publish field, the record's value matches the published when value, for example status = published.
  3. The record is not in the trash.

Only fields marked Visible in public API are included. Everything else, including internal fields, drafts and other entities, returns 404, exactly as if it didn't exist.

Endpoints

The workspace is identified by its slug in the URL:

PathDescription
GET /api/v1/public/{slug}/entities/{key}/recordsList published records
GET /api/v1/public/{slug}/entities/{key}/records/{id}One published record
GET /api/v1/public/{slug}/media/{id}/fileA file used by published content

Listing supports the same page, pageSize, sort, filter, search, fields and expand parameters as the REST API, limited to public fields. Expanded relations include only public, published target records.

Caching

Record responses are sent with Cache-Control: public, max-age=60, stale-while-revalidate=300, and media files with one hour. Put a CDN in front for high traffic.

Media files

A file is served publicly only while a published, public record references it through a public media field. Unpublishing the record makes the file private again. Build image URLs like this:

js
const imageUrl = (slug, mediaId) => `https://cms.example.com/api/v1/public/${slug}/media/${mediaId}/file`;

Example: fetch with JavaScript

js
const CMS = 'https://cms.example.com/api/v1/public/acme';

export async function getArticles(page = 1) {
  const url = new URL(`${CMS}/entities/article/records`);
  url.searchParams.set('sort', '-publishedAt');
  url.searchParams.set('expand', 'author,category');
  url.searchParams.set('page', String(page));
  const res = await fetch(url);
  if (!res.ok) throw new Error(`CMS error ${res.status}`);
  return res.json(); // { data: [...], meta: { page, pageSize, total, totalPages } }
}

export async function getArticle(slug) {
  const res = await fetch(`${CMS}/entities/article/records?filter[slug]=${encodeURIComponent(slug)}&expand=author,tags`);
  const { data } = await res.json();
  return data[0] ?? null;
}

Example: a blog in Next.js

tsx
// app/blog/page.tsx
const CMS = process.env.CMS_URL + '/api/v1/public/acme';

export const revalidate = 60;

export default async function Blog() {
  const res = await fetch(`${CMS}/entities/article/records?sort=-publishedAt&expand=author`);
  const { data } = await res.json();
  return (
    <main>
      {data.map((article: any) => (
        <a key={article.id} href={`/blog/${article.data.slug}`}>
          <h2>{article.data.title}</h2>
          <p>{article.data.excerpt}</p>
          <small>by {article.data.author?.data.name}</small>
        </a>
      ))}
    </main>
  );
}

The same requests work from Vue/Nuxt, Astro, SvelteKit, mobile apps or any HTTP client.

Need drafts or private fields?

Use the authenticated REST API with an API key that has the records:read scope, from your server only. Never put API keys in browser code.

ByteContent by ByteRings is open source under the MIT License. Edit on GitHub