nullbackend-sdk
v0.3.1
Published
Official JavaScript/TypeScript SDK for nullbackend.pro
Maintainers
Readme
nullbackend-sdk
Official JavaScript/TypeScript SDK for nullbackend.pro.
Works in the browser (React, Next.js, Vite, plain HTML with a bundler) and in Node.js 18+.
Install
npm install nullbackend-sdkUsage
import { init } from 'nullbackend-sdk';
const client = init({
publicKey: 'pk_live_xxx', // from your nullbackend.pro project dashboard
// baseUrl defaults to https://api.nullbackend.pro
// override it for local testing, e.g. baseUrl: 'http://localhost:3001'
});
const products = await client.products.list();
const created = await client.products.create({ name: 'Keyboard', price: 49.99 });
await client.products.update(created.id, { price: 39.99 });
await client.products.delete(created.id);Custom API endpoints
Define your own endpoints from the dashboard (Project → API Builder), then call them from any client:
// POST /v1/data/users { name: "Alice", age: 30 }
const user = await client.api.post('users', { name: 'Alice', age: 30 });
// GET /v1/data/users
const users = await client.api.get('users');
// PATCH /v1/data/users/abc123
await client.api.patch('users/abc123', { age: 31 });
// DELETE /v1/data/users/abc123
await client.api.delete('users/abc123');
// Custom method/path escape hatch
await client.api.request('PUT', 'posts/42', { title: 'Hello' });API
Client factory
init({ publicKey, baseUrl? })→client
client.auth
client.auth.register({ email, password })client.auth.login({ email, password })client.auth.me()client.auth.logout()
client.products
client.products.list()client.products.get(id)client.products.create({ name, price })client.products.update(id, { name?, price? })client.products.delete(id)
client.api — custom endpoints
client.api.get(path)client.api.post(path, body)client.api.put(path, body)client.api.patch(path, body)client.api.delete(path)client.api.request(method, path, body?)
Session
client.setAccessToken(token)— attach a Bearer tokenclient.clearAccessToken()— remove the token
License
MIT
