Skip to content

Connecting Your App

Every PocketBase instance on PocketBase Cloud exposes a standard PocketBase REST + realtime API over HTTPS. The easiest way to talk to it is the official JavaScript SDK, which works in the browser, Node.js, Deno, Bun, and React Native.

Step 1: Install the SDK

npm install pocketbase

Step 2: Find your instance URL

Using the portal

Open the instance from your project’s PocketBase tab — the detail page lists the App URL and the admin URL, and Connect Your App shows a ready snippet with the App URL filled in.

Using the CLI

pbc pocketbase info --name my-app-db          # URL, version, admin login
pbc pocketbase info --name my-app-db --json   # same, machine-readable

Inside a bound directory, plain pbc pocketbase info does it.

Step 3: Create a client

Point the client at that URL:

import PocketBase from "pocketbase";

const pb = new PocketBase("https://<instance-name>.pocketbasecloud.com");

That’s it — no API keys or extra configuration. HTTPS and CORS are already handled by the platform.

Step 4: Make your first request

// list records from a collection
const posts = await pb.collection("posts").getList(1, 20, {
  sort: "-created",
});

// fetch a single record
const post = await pb.collection("posts").getOne("RECORD_ID");

// create a record
const newPost = await pb.collection("posts").create({
  title: "Hello from PocketBase Cloud",
});

Which operations are allowed for unauthenticated or authenticated users is controlled by each collection’s API rules.

Using environment variables

Hard-coding the instance URL works, but most apps keep it in an environment variable so staging and production can point at different instances:

const pb = new PocketBase(import.meta.env.VITE_POCKETBASE_URL);

If you host your app on PocketBase Cloud, you don’t need to set it. Every website and service in a project gets its PocketBase’s address automatically on every deploy, as POCKETBASE_URL, VITE_POCKETBASE_URL, NEXT_PUBLIC_POCKETBASE_URL and PUBLIC_POCKETBASE_URL. Websites get it at build time and services at runtime. In a preview or environment, each copy of your app gets that environment’s PocketBase instead. The Variables page of a service, and Build variables of a website, show it under From PocketBase. A website uploaded already built can’t get the address: deploy its source code instead. A project with several PocketBases (older projects) gives no address automatically.

To point somewhere else, set the same name yourself on the app’s Variables page or from the CLI; your value always wins:

pbc env set POCKETBASE_URL=https://my-app-db.pocketbasecloud.com \
  --target backend --name my-app-api

See backend environment variables.

Checking the API before you wire it up

Using the portal

Each collection’s API preview in the instance’s admin panel shows the exact REST endpoints and lets you copy example requests.

Using the CLI

pbc talks to any PocketBase instance, which makes it a quick way to confirm an endpoint from the shell:

pbc admin use https://<instance-name>.pocketbasecloud.com
pbc admin login                 # superuser
pbc admin collections ls
pbc admin records ls posts --per-page 5

Note that these commands run as the superuser, so they bypass API rules — use an unauthenticated curl to see what your app’s users actually get.

Other languages

PocketBase has an official Dart SDK for Flutter apps, and community SDKs for Go, Python, Rust, and more. Any HTTP client works too — the full REST API is documented in your instance’s admin panel under API preview on each collection.

Next steps