Skip to content

Backend only

Backend only (headless)

Rebase has two shapes, and this page is the one that never opens a browser: a REST API, auth, storage, realtime and backups over a PostgreSQL database you already have. No admin panel, no backend/schema/. If you were reaching for Supabase or PostgREST, this is the comparable thing.

Everything on this page also works in the full project — it is the same server. What --headless removes is the frontend package and the table files, not a capability.

pnpm dlx @rebasepro/cli init my-api --headless --yes
cd my-api

One workspace, no frontend/:

Folder What is in it
backend/ storage.ts (storageAuthorize), your custom functions and crons, and the backend/schema/ that --introspect writes, when you ask for it. There is no server file — the published runtime boots the project

--template has no effect here: a preset seeds tables, and this flavour has none. Node 22.22+, the same floor as the full project — the headless overlay’s package.json declares "node": ">=22.22.0" and replaces the one under it.

init generates a ready-to-run .env. To use a database you already run, pass its URL at scaffold time:

pnpm dlx @rebasepro/cli init my-api --headless --database-url "postgres://user:pass@host:5432/db" --yes

Or set DATABASE_URL in .env afterwards — it is the same thing. With no DATABASE_URL, rebase dev starts a managed PostgreSQL (PGlite) in the project directory, which is useful for trying the API out but is not what this flavour is for.

Then:

pnpm install
pnpm run dev

Read the URL from the output. rebase dev derives a free port from the project’s path rather than using a fixed one, so it differs between projects and between machines.

There are none in code: with no backend/schema/index.ts, the backend declares no tables. The server reads your database schema at boot and serves the tables it finds, so the API follows your migrations: change the schema, and the endpoints change with it.

A table is served once row-level security is enabled on it. With no policy it is served and returns no rows, and boot warns about it; a policy opens it:

ALTER TABLE your_table ENABLE ROW LEVEL SECURITY;
-- rebase.uid() is text: the cast makes this work for a uuid or integer column too.
CREATE POLICY your_table_owner ON your_table
FOR ALL USING (user_id::text = rebase.uid());

rebase.uid(), rebase.roles() and rebase.jwt() are installed by Rebase and read the identity of the authenticated request. See Row-level security for the policy vocabulary, and rls-check for an audit of what your policies actually allow.

A table without RLS is skipped, deliberately: every authenticated request runs as rebase_user, so serving a table that row-level security does not guard would hand every row to every signed-in caller. Each skipped table is named at boot along with the SQL that would protect it.

A join table is not served either way: it is read as the link between the two tables it joins. One with RLS off is named at boot too.

The check runs at boot. If RLS is disabled on a served table later, it stays served until the next boot skips it. The scheduled audit reports it sooner, and is off by default.

If you would rather have the tables written down as TypeScript — for types, for hooks, for review — introspect them:

pnpm dlx @rebasepro/cli init my-api --headless --database-url "postgres://…" --introspect --install

--introspect implies --template blank and needs --install, because it runs against the installed CLI. In an existing project the same thing is:

pnpm rebase schema introspect

Files land in backend/schema/: one defineTable per table, with its columns, relations and its policies as rls, and an index.ts exporting them. From that point the project has tables in code and the boot-time introspection stops being what defines the API.

The headless scaffold installs Atlas in backend/, so rebase db push, rebase db generate and pnpm run db:migrate work on those tables as in any project.

Over HTTP:

curl "$REBASE_URL/api/data/posts?limit=10"

Or with the type-safe client, which is a dependency of the headless scaffold already:

import { createRebaseClient } from "@rebasepro/client";
// The URL `rebase dev` printed, or your deployment's. `pnpm example` reads it
// from `.rebase-dev-url` when the variable is unset.
const rebase = createRebaseClient({ baseUrl: process.env.REBASE_URL! });
const { data: posts } = await rebase.data.table("posts").find({
where: { published: ["==", true] },
limit: 10
});
  • REST API — the endpoint shapes, filters and errors
  • Typed SDK — querying, auth, realtime, storage
  • /api/docs — the OpenAPI document, served by the running backend once it serves a table, to a signed-in caller (the tables they may see). Set REBASE_ENABLE_SWAGGER=true to publish it to everyone, with the Swagger UI at /api/swagger outside production. A project with no table serves neither: the document is generated from the tables

If every data request answers with this:

{
"error": {
"message": "This project serves no tables yet. …",
"code": "NO_TABLES"
}
}

then the project declares no tables in code and the database gave it nothing to serve. Before 0.31 the code was NO_COLLECTIONS. It is the expected first response from a headless project pointed at an empty database, and it is a 404 rather than a 500 because nothing is broken — there is simply nothing to serve yet.

Three things resolve it, in the order worth checking:

  1. The database has no tables. Create them — a migration, plain SQL, or a defineTable file plus rebase db push — and restart.
  2. The tables do not have row-level security enabled, so boot skipped them. The boot log names each one, with the SQL. Enable it and add a policy, as above. The response says so too: its message names the tables and gives the ALTER TABLE … ENABLE ROW LEVEL SECURITY for them, and details.unprotectedTables lists them.
  3. DATABASE_URL points somewhere else than you think. rebase status prints the three files that decide what the backend reaches.

Nothing here locks you out of it. One command adds the frontend/ that rebase init without --headless would have written, with its workspace and its app in rebase.json:

pnpm rebase apps add admin # at /, or at /admin when another app is at /
pnpm rebase apps add admin --path /admin
pnpm install
pnpm run dev

It writes what rebase init without --headless would have, from the same templates:

  • frontend/, with rebaseBackendGuard() in its Vite config. The admin renders every table the backend serves, from GET /api/schema/tables, with no file per table; the users customization comes with it only when backend/schema/users.ts declares the auth table as the scaffold does. The panel’s own customizations go in frontend/src/cms/.
  • the admin app in rebase.json, with cms at its path and a build command in the project’s package manager. A project with no rebase.json gets one.
  • frontend in package.json’s workspaces and in pnpm-workspace.yaml.
  • with tables in code (backend/schema/index.ts, by hand or from rebase schema introspect), the scaffold’s db:push, db:generate and schema:generate scripts, the backend build that runs rebase schema generate first, and ts-morph. A script you changed is kept, and named.

Every @rebasepro/* package is pinned to the version the project already uses (its @rebasepro/server first), not the CLI’s. A project that pins only link: or workspace: specs gets the CLI’s version, and is told so.

It refuses when frontend/ exists, when an app is already named admin or declares the CMS, or when --path is taken or is not a path an app can be served at. A refusal changes nothing, and neither does a write that fails part way: every file is put back. With --json it prints what it wrote, or the error envelope. See Frontend Setup for the frontend itself.