NotifyHub Docs

Getting Started

NotifyHub is a multi-channel notification infrastructure that lets you send in-app, email, push, and SMS notifications using a single API.

Install SDK

Import the Notification Client into your frontend project.

npm install @notifyhub/sdk
bash

Quick Integration

Initialize the client and connect to the real-time notification stream.

import { NotificationClient } from '@notifyhub/sdk';

const client = new NotificationClient({
  baseUrl: 'https://api.notifyhub.io',
  apiKey: 'YOUR_PUBLIC_API_KEY'
});

client.on('notification', (data) => {
  console.log('New notification:', data);
});

client.connect();
javascript

Authentication

NotifyHub uses two types of authentication depending on the context:

Client Side

Public API Key

Used in frontend apps to identify your project and enable device registration and stream connection.

Server Side

JWT / Secret Key

Used for authenticated requests like sending notifications or managing user data via the REST API.

Using API Keys

Include your API key in the headers of your requests.

curl -X POST https://api.notifyhub.io/api/notifications/send \
  -H 'x-api-key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"subject": "Hello", "body": "World"}'
bash

SDK Reference

The NotificationClient provides the following methods to interact with the notification system:

connect(token?, identity?)

Authenticates and opens an SSE stream to the backend.

  • token: Optional JWT for private streams.
  • identity: Optional user ID to receive targeted notifications.

subscribe(topic)

Subscribes to a specific broadcast topic (e.g. "news", "updates").

registerDevice(params)

Registers a browser/device to receive push notifications.

await client.registerDevice({
  deviceId: 'unique-id',
  platform: 'web',
  identity: 'user-123'
});
javascript

on(event, callback)

Listen for SDK events: 'notification', 'connected', 'disconnected', 'error'.


REST API

POST/api/notifications/send

Send a notification to a specific user, topic, or all users.

Payload

{
  "channel": "in_app", 
  "identity": "user-123",
  "subject": "New Message",
  "body": "You have a new message!",
  "metadata": {
    "url": "/messages/123",
    "image": "https://example.com/icon.png"
  }
}
json
POST/api/notifications/device/register

Register a new device for a user identity.

GET/api/notifications/logs

Retrieve delivery logs for your project.


Real-time Stream

NotifyHub uses Server-Sent Events (SSE) for real-time communication. This provides a lightweight, unidirectional channel with automatic reconnection.

Stream Workflow

  1. Handshake: Client opens a connection to /api/notifications/stream.
  2. Identity: The connection is associated with a user identity or topic.
  3. Dispatch: When an event occurs, the broker pushes it to matched listeners.
  4. Recovery: If connection drops, the SDK automatically re-establishes it.

Ready to Explore?

The best way to understand NotifyHub is to see it in action.