JavaScript SDK

Use the SDK in the browser or Node to talk to the API and subscribe to real-time events.

Install

npm bash
npm install onlybase-sdk
bun bash
bun add onlybase-sdk

Quick start

Create a client with your API key. Point baseUrl to your API (e.g. https://api.onlybase.app in production).

Browser or Node javascript
import { only } from 'onlybase-sdk';

const apiKey = 'YOUR_API_KEY';

const users = only(apiKey).collection('users');

Collections

All methods return a Promise. Responses have a data (and optional error ) shape.

Create row(s)

const result = await users.create({ email: 'a@b.com', name: 'Alice' });
// or array: await users.create([{ email: 'a@b.com' }, { email: 'b@c.com' }]);

List rows

const { data } = await users.list({
  limit: 100,
  offset: 0,
  orderBy: 'id',
  order: 'desc'
});

Get one row

const { data } = await users.one('1');

Update row

await users.update('1', { name: 'Alice Updated' });

Delete row

await users.delete('1');

Real-time

Subscribe to insert, update, or delete events. The SDK connects via WebSocket and auto-reconnects. Call unsubscribe() to close.

Subscribe javascript
const sub = users.subscribe('insert', (message) => {
  console.log(message.event, message.collection, message.payload);
});

// later
sub.unsubscribe();

Events: 'insert', 'update', 'delete'.