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.
Scaffold it
Section titled “Scaffold it”pnpm dlx @rebasepro/cli init my-api --headless --yescd my-apiOne 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.
Point it at your database
Section titled “Point it at your database”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" --yesOr 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 installpnpm run devRead 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.
Where the tables come from
Section titled “Where the tables come from”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.
Generating table files instead
Section titled “Generating table files instead”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 introspectFiles 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.
Use it
Section titled “Use it”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). SetREBASE_ENABLE_SWAGGER=trueto publish it to everyone, with the Swagger UI at/api/swaggeroutside production. A project with no table serves neither: the document is generated from the tables
404 NO_TABLES
Section titled “404 NO_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:
- The database has no tables. Create them — a migration, plain SQL, or a
defineTablefile plusrebase db push— and restart. - 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 SECURITYfor them, anddetails.unprotectedTableslists them. DATABASE_URLpoints somewhere else than you think.rebase statusprints the three files that decide what the backend reaches.
Adding an admin panel later
Section titled “Adding an admin panel later”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 /adminpnpm installpnpm run devIt writes what rebase init without --headless would have, from the same
templates:
frontend/, withrebaseBackendGuard()in its Vite config. The admin renders every table the backend serves, fromGET /api/schema/tables, with no file per table; theuserscustomization comes with it only whenbackend/schema/users.tsdeclares the auth table as the scaffold does. The panel’s own customizations go infrontend/src/cms/.- the
adminapp inrebase.json, withcmsat its path and a build command in the project’s package manager. A project with norebase.jsongets one. frontendinpackage.json’sworkspacesand inpnpm-workspace.yaml.- with tables in code (
backend/schema/index.ts, by hand or fromrebase schema introspect), the scaffold’sdb:push,db:generateandschema:generatescripts, the backend build that runsrebase schema generatefirst, andts-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.
Next steps
Section titled “Next steps”- Authentication — providers, tokens, API keys
- Row-level security — the access model
- Custom Functions — your own routes
- Deployment — taking it to production