instantbackend-sdk
v1.1.0
Published
Official JavaScript SDK for InstantBackend - A simplified backend API with authentication and collection management
Maintainers
Readme
InstantBackend SDK
Official JavaScript SDK for InstantBackend - A simplified backend API with authentication and collection management.
Installation
npm install instantbackend-sdkUsage
Import
// ES6 Modules
import { InstantBackend } from 'instantbackend-sdk';
// CommonJS
const { InstantBackend } = require('instantbackend-sdk');Initialization
const sdk = new InstantBackend('your-api-key');Authentication
// User login
const authResponse = await sdk.login('username', 'password');
// JWT token is automatically stored in the instanceCollection Management
// Get a collection reference
const users = sdk.collection('users');
// Add a document
const newUser = await users.add({
name: 'John',
email: '[email protected]'
});
// Query documents with filters
const results = await users
.where('email', '==', '[email protected]')
.limit(10)
.sort('asc')
.get();
// Get a document by ID
const user = await users.doc('document-id');API Reference
InstantBackend
Constructor
new InstantBackend(apiKey, jwtToken?)apiKey(string, required): Your InstantBackend API keyjwtToken(string, optional): JWT token for authentication
Methods
collection(name): Gets a reference to a collectionlogin(username, password): Authenticates a user and gets a token
Collection
Methods
add(data): Adds a document to the collectionwhere(field, operator, value): Adds a filter to the querylimit(n): Limits the number of resultssort(order): Sets the sort order ('asc' or 'desc')nextToken(token): Sets the pagination tokenget(): Executes the query and gets the resultsdoc(id): Gets a document by its ID
License
MIT
