Skip to main content

Introduction

Brook is a real-time fault-tolerant pub/sub SDK for JavaScript, Go, and React applications. It provides WebSocket connectivity with automatic reconnection, message replay for missed messages, and seamless integration with your favorite frameworks.

Features

  • Real-time messaging with WebSocket
  • Automatic reconnection with exponential backoff
  • Message replay for missed messages
  • React hooks for seamless integration
  • Lightweight and performant
  • Full TypeScript support

Installation

Package Manager

Install Brook SDK using your preferred package manager:
  • npm
  • pnpm
  • yarn
npm install @aptly-sdk/brook

CDN (Browser)

For quick prototypes or simple HTML pages, use the CDN version:
<script type="module">
  import Brook from 'https://cdn.jsdelivr.net/npm/@aptly-sdk/[email protected]/+esm';

  const client = new Brook({ apiKey: 'your-api-key' });
  // Your code here...
</script>
See the JavaScript SDK guide for a complete browser example.

Get Your API Key

Before using the Brook SDK, you’ll need to get your API key from the Console.
1

Visit the Console

2

Sign in or create an account

Create a new account or sign in to your existing account
3

Generate API Key

Copy your API key from the dashboard
Keep your API key secure and never commit it to version control. Use environment variables to store it safely.

Understanding Key Types

Aptly provides two types of API keys:
  • Public Key (pk_)
  • Server Key (sk_)
For client-side applicationsUse public keys in browsers, mobile apps, and any client-side code. These keys are protected by origin validation.
// Safe to use in frontend code
const client = new Brook({ apiKey: 'pk_abc123...' });

Learn More About Authentication

Read the complete guide on Public Keys vs Server Keys

Quick Start

  • JavaScript
  • React
  • Go
  • Browser/CDN
import Brook from '@aptly-sdk/brook';

// Initialize the client
const client = new Brook({ apiKey: 'your-api-key' });

// Connect to the server
await client.connect();

// Create a channel
const channel = client.realtime.channel('my-topic');

// Subscribe to messages
channel.stream((message, metadata) => {
  console.log('Received:', message);
  console.log('Metadata:', metadata);
});

// Publish a message
await channel.publish({ text: 'Hello World!' });

Next Steps

Demo

Check out our Live Demo to see Brook in action.