Connect with the SDK
voidbase answers PocketBase's API, so the client library is PocketBase's, installed from npm and pointed at your instance. Nothing about it is voidbase-specific.
Install it
bun add pocketbase # or: npm install pocketbaseUse it
The only thing you supply is the address of your instance. Everything after that is the SDK's own API, and works exactly as its documentation says.
import PocketBase from "pocketbase";
const pb = new PocketBase("https://your-instance.example.com");
// sign in; the token is kept in pb.authStore and sent with every request after this
await pb.collection("users").authWithPassword("you@example.com", "your-password");
// read, with filtering, sorting and related records in one call
const posts = await pb.collection("posts").getList(1, 20, {
filter: "published = true && author.verified = true",
sort: "-created",
expand: "author",
});
// write
await pb.collection("posts").create({ title: "Hello", body: "...", author: pb.authStore.record?.id });
// and follow changes as they happen, over one connection
pb.collection("posts").subscribe("*", (e) => console.log(e.action, e.record));The auth token lives in pb.authStore, so signing in once covers the rest of the session, and in a browser it is persisted for you. File URLs come from pb.files.getURL(record, filename), with a thumb option for a resized version.
One SDK instance for the whole application is the intended pattern on the client side. On a server, make one per request instead, so one user's token never leaks into another user's call.
Where to read on
All of this applies to voidbase without translation:
- The JavaScript SDK every method, and the SDKs for other languages, which speak the same API
- Records API what each endpoint accepts and returns
- API rules and filters the query and permission language
- Authentication password, OAuth2, one-time codes and multi-factor sign-in
- Files uploads, protected files and thumbnails
No instance to point at yet? Run one in about a minute.
Fix it yourself. The link below opens this file in GitHub's editor and forks the repository for you if you need one, and your change becomes a pull request without leaving the browser.