Skip to Content
You Don't Need a Backend

You Don’t Need a Backend

Most platforms that call themselves a backend still expect you to run one. You end up with an API tier whose whole job is to hold a privileged key and forward requests — a layer you have to deploy, secure and pay for, sitting between your app and the service you already pay to be your backend.

Foir is built so that layer doesn’t exist. Your app talks to Foir directly. Where you have logic of your own, you write it as a function and Foir is the only thing that can call it.

The shape

Your app (browser, mobile, anything) │ │ one publishable key ▼ Foir ── authentication · authorization · rate limits · quotas ──┐ │ dispatches, signed │ ▼ ┌──────────────────────────────────┐ │ Your function, hosted anywhere │ │ · verifies the token, or 401s │ │ · holds no credentials │ └──────────────────────────────────┘

Three things are true of that picture, and each one removes something you’d otherwise build.

Your function is not publicly callable. Foir signs every dispatch, and your endpoint refuses anything that doesn’t carry a valid signature. Two lines with the SDK:

import { verifyScopedToken } from '@foir/sdk/server'; const token = request.headers.get('X-Foir-Token'); if (!token) return new Response('Unauthorized', { status: 401 }); await verifyScopedToken(token, jwksUrl); // throws unless Foir signed it

That check is the whole security boundary. You are not writing authentication — you’re verifying that Foir, which already did, is the caller.

It is the whole boundary because of the next point: the function holds nothing of its own, so everything it can do it does with that token, and Foir holds the token to the project it was signed for. A function that does hold something of its own (a vendor key in its environment, its own database) must also hold the caller to its own project, because Foir signs a token for every project’s dispatches: requireScopedToken(request, { expectedProjectId }) does both checks in one call.

Your function holds no credentials. Not the third party’s, not Foir’s. Secrets live in Foir’s vault, and the token every call carries reads them: it grants the project’s secrets and nothing else.

// the token that came with the call reads the key when it is needed await fetch(`${FOIR_API_URL}/graphql`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Foir-Token': token }, body: JSON.stringify({ query: 'query($ref: String!, $purpose: String!) { getSecret(ref: $ref, purpose: $purpose) { plaintextBase64 } }', variables: { ref: RESEND_KEY_REF, purpose: 'send_email' }, }), });

The key is never in your repository, your environment, or your deploy pipeline: they hold a reference. See Secrets.

Foir decides who may trigger it. Not a rule you write and maintain — a permission on an API key. Which brings us to the part people usually assume needs a server.

Calls from people who aren’t signed in

A contact form has nobody signed in. Neither does a newsletter signup, a waitlist, or a high-score board. This is the case that normally forces an API tier into existence: you can’t put a write credential in a page, so you build a route that holds one, and now you have an open endpoint in front of a more privileged key than the browser would have had.

Foir handles it directly. A publishable key carries an explicit list of what it gives a stranger: the reads a visitor needs, and two forms that let one submit.

records:read read what the storefront shows records:create:contact_submission take a submission into one model operations:execute:request_a_quote run one named operation

Beside the reads, those two forms are all that exists. No update, no delete, no publish, no wildcards: the platform refuses them. A stranger submits; they do not revise, remove or promote. You set this in the console under What anyone can do without signing in, and everything you don’t tick stays impossible. Nothing is given that the list does not name, the reads included, so a key with an empty list lets a visitor do nothing.

Or declare it with the key in foir.config.ts, where the rest of the storefront already lives:

apiKeys: [ { name: 'Storefront', kind: 'publishable', envVar: 'FOIR_PUBLIC_KEY', grants: ['records:read'], baselineGrants: ['records:read', 'records:create:contact_submission', 'operations:execute:request_a_quote'], allModels: true, }, ],

foir push mints the key with the list, or changes the list on the key you already have, which keeps its secret. The change is live when the push finishes. An entry that names a model or an operation the config does not declare is refused by name, before anything is sent. The same list is --baseline-grants on foir api-keys create and foir api-keys update.

What limits a stranger is the public API’s rate limit, which counts every request made with the key, and any quota you declare on the operation or the model. Foir adds no allowance of its own on top, so a form or a checkout that strangers use takes as many submissions as your key’s limit allows.

What you get for free on those calls: the public API’s rate limit, the operation’s own quotas and preconditions, and the organization the submission belongs to stamped on the row. A hand-rolled route gives you none of that unless you write it.

A newsletter sign-up records the opt-in in the same run. The form runs one operation, given to a stranger by name as request_a_quote is above. The operation declares what it does for the person who signed up:

operations: [ { key: 'subscribe', name: 'Subscribe', endpoint: 'https://example.com/api/subscribe', grants: ['notifications:consent', 'users:create'], }, ],

Its handler records the opt-in for the address it was sent, with the app client and the token the run was dispatched with:

await foir.notifications.setConsent({ email, category: 'marketing', channel: 'email', enabled: true, locale });

Foir finds the user who holds the address, or makes one, together with the change, so an opt-in it refuses leaves no user behind. notifications:consent sets a preference only in a category the project makes opt-in, and only an operation holds it: a publishable key and a visitor never do. In a category that confirms opt-ins by email, the preference switches on when the user follows the link they are sent.

A row submitted this way is owned by nobody — that’s what makes it safe to accept from a stranger. It’s also why a signed-in user is sent to createModel instead: their submission should be theirs, and appear in their own records.

What surrounds your code

Everything in this list is machinery you would otherwise build and keep working:

AuthenticationUsers, sessions, OAuth, one-time codes, hosted sign-in on your own domain
AuthorizationEnforced in the database, below your code, so a forgotten filter can’t leak data
DispatchRetries, backoff, dead letters, and a log of every run
LimitsPer key, and the quotas you declare per operation
PreconditionsRefuse a run unless something is true of the request or the caller
Second factorRequire a proven step-up before an operation runs at all
OrganizationsEvery run and every row carries the level it belongs to

When you do still need a server

Two cases, stated plainly so the rest of this page is believable.

Receiving webhooks from someone else. Stripe, Shopify and their like post to a URL you own. Something has to be at that URL. It can be small, and it can be the same deployment your operation endpoints live in.

Sessions that aren’t Foir’s. If you’re holding a session for another system — a Shopify customer account, your own SSO — that lives with you.

What neither requires is an API tier in front of Foir. They’re endpoints of their own, doing their own jobs.

A server that renders your pages is not a third case either. It reads what the visitor may read, as the visitor, so it is not an API tier: see A server rendering your pages for the key it holds and how it names each visitor.

Previewing drafts is not a third case. A preview environment is a deployment of the same app with its own publishable key, and that key holds drafts:read; the key your production app ships does not. See Preview Mode Access.

Where to go next

Last updated on