Quickstart

Get realtime events flowing in under 5 minutes.

1. Create an App

After signing up, go to your dashboard and create a new app. You'll get three credentials:

  • App ID — identifies your app
  • Key — public key used by client connections
  • Secret — private key for server-side API calls (never expose to clients)

2. Connect from the Browser

Include the Relay JS client (or use pusher-js — they're compatible):

<script src="/js/relay.js"></script>
<script>
const relay = new Relay('your-app-key', {
    wsHost: 'your-relay-host.com',
    wsPort: 6001,
    forceTLS: false,
    cluster: 'mt1',
});

const channel = relay.subscribe('notifications');
channel.bind('new-message', (data) => {
    console.log('Received:', data);
});
</script>

Or with pusher-js (zero code changes):

<script src="https://js.pusher.com/8.0/pusher.min.js"></script>
<script>
const pusher = new Pusher('your-app-key', {
    wsHost: 'your-relay-host.com',
    wsPort: 6001,
    forceTLS: false,
    enabledTransports: ['ws'],
    cluster: 'mt1',
});

pusher.subscribe('notifications').bind('new-message', (data) => {
    console.log(data);
});
</script>

3. Trigger Events from Your Server

Use the REST API to send events:

curl -X POST https://your-relay-host.com/api/v1/apps/YOUR_APP_ID/events \
  -H "X-Relay-Key: YOUR_KEY" \
  -H "X-Relay-Secret: YOUR_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "new-message",
    "channels": ["notifications"],
    "data": "{\"text\": \"Hello from the server!\"}"
  }'

Or with a Bearer token:

curl -X POST https://your-relay-host.com/api/v1/apps/YOUR_APP_ID/events \
  -H "Authorization: Bearer YOUR_APP_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "new-message",
    "channels": ["notifications"],
    "data": "{\"text\": \"Hello!\"}"
  }'

4. See it Live

Open the Debug Console in your app dashboard to see events flowing in real-time.

Next Steps