Skip to main content
Get started with the SnackBase JavaScript SDK in this 5-minute guide. You’ll learn how to initialize the client, authenticate users, and perform CRUD operations on your collections.

Prerequisites

  • Complete the Installation guide
  • Have a SnackBase instance running with an existing collection
  • Have your API URL ready (e.g., https://your-project.snackbase.dev)

Step 1: Initialize the Client

Create a new SnackBase client instance with your configuration:
For client-side applications, omit the apiKey parameter. Users will authenticate with their own credentials.

Step 2: Authenticate a User

Email and Password

Register a New User

Step 3: Query Records

List Records

Get a Single Record

Using the Query Builder

For complex queries, use the fluent query builder:

Step 4: Create Records

Step 5: Update Records

Full Update (PUT)

Replaces all fields of the record:

Partial Update (PATCH)

Updates only the specified fields:
Use patch() for partial updates to avoid overwriting fields you don’t intend to change.

Step 6: Delete Records

Step 7: Real-Time Subscriptions

Subscribe to real-time updates for a collection:

Complete Example

Here’s a complete example combining all concepts:

Next Steps

Check out the Feature Voting App for a complete example demonstrating authentication, CRUD operations, real-time subscriptions, and React integration with the SDK.