nextjs template of bijection init.
Alternatively see the
Pages Router
version of this quickstart.
1
Install the Bijection CLI
bijection is not on your PATH afterwards, add it as the installer
explains. See Install Bijection.2
Create the app
my-app/, then
installs the app’s dependencies, including the Bijection SDK, with your
JavaScript package manager: the one of an enclosing workspace, otherwise
the first of pnpm, bun, yarn and npm on your PATH. The app needs Node.js
and one of them; the backend does not. Last, it generates
bijection/_generated/, the typed API of your functions, so the project
typechecks before it has a deployment.3
Log in
Log this machine in to Bijection. You only do this once per machine.
Bijection’s hosted service is not yet open for public sign-up, and the CLI
has no default management service. Before running
bijection login, set
BIJECTION_MANAGEMENT_URL to the management service URL you were given, in
your shell’s startup file so that every later bijection command sees it too:4
Start the backend
.env.local, where the app reads it as NEXT_PUBLIC_BIJECTION_URL.
bijection dev then keeps running: on every change it pushes bijection/
to your dev deployment and regenerates bijection/_generated/. Keep it
running.5
Start the app
In another terminal, start the Next.js development server with the command
Open http://localhost:3000 and send a message.
Open a second window: messages appear in both as soon as they are sent.
bijection init printed for your package manager, for example:6
Read the backend
bijection/schema.ts declares the messages table, and
bijection/messages.ts exports a query and a mutation. Each export is an API
function named after the file and the export: api.messages.list and
api.messages.send.bijection/messages.ts
7
Read the app
BijectionProvider needs a BijectionReactClient, and both run in the
browser, so app/BijectionClientProvider.tsx is a client component:app/BijectionClientProvider.tsx
app/layout.tsx wraps the body in <BijectionClientProvider>, and
app/page.tsx, also a client component, subscribes to the query with
useQuery and calls the mutation with useMutation. The query result
updates by itself whenever the messages change:app/page.tsx
8
Call a function from the CLI
With the app open, send a message from another terminal. It appears in the
app at once: