WebSocket API for Elbia Lambda

Real-time, bidirectional communication with Elbia Lambda's serverless infrastructure.

Get Started

Overview

Elbia Lambda's WebSocket API enables real-time, full-duplex communication between client and server. This guide covers authentication, connection setup, available methods, and event handling.

Key Features

  • Real-time bidirectional communication
  • Automatic session persistence
  • Secured with OAuth 2.0
  • Message rate limiting

Connection Flow

1. Establish WebSocket connection with authentication token
2. Receive session confirmation event
3. Send/receive application/data messages
4. Gracefully close connection when done

Getting Started

1. Requirements

  • Elbia Lambda account
  • Valid API token with scopes
  • WebSocket library compatible client

2. Connect to WebSocket

// JavaScript Example
const socket = new WebSocket('wss://api.elbialambda.cloud/v1/ws', {
    headers: {
        'Authorization': "Bearer YOUR_API_TOKEN"
    }
});

Replace YOUR_API_TOKEN with your actual API token from the dashboard.

Methods

connect()

Establish secure WebSocket connection to Elbia Lambda API.

Parameters

  • - apiToken (string): Valid OAuth token
  • - region (string): Preferred server location
  • - channel (string): WebSocket topic

Response

Connection established with 201 Created handshake.

publishMessage()

Send message to connected channel.

Parameters

  • - channelId (string)
  • - payload (object): JSON data

Response

Returns MessageId for tracking.

subscribeToChannel()

Subscribe to receive updates from specific channel.

Parameters

  • - channelId (string)
  • - filters (object): Subscription filters

Response

Confirmation payload with subscription status.

Events

onMessageReceived

→ client

Fired when a new message is received from the server.

{
  "event": "message_received",
  "channel_id": "CH_43210987654321",
  "data": {
    "temperature": 22.5,
    "location": "warehouse-42"
  }
}

onChannelClosed

→ server

Notification when a channel is terminated.

{
  "event": "channel_closed",
  "reason": "rate_limit_exceeded",
  "code": 429
}

onSubscriptionUpdated

→ client

Updates about active subscriptions and filters.

{
  "event": "subscription_updated",
  "channel_id": "CH_98765432109876",
  "subscription": {
    "filter": {
      "type": "device",
      "location": "warehouse-42"
    }
  }
}

Best Practices

Rate Limit Awareness

Implement backoff strategy when handling rate limiting. Wait for 429 Too Many Requests events.

const retryDelay = 2^n * 1000;

Channel Management

Use subscribeToChannel().close() when no longer needing updates.

socket.addEventListener('close', () => { console.log('Connection closed'); });

Data Formats

Always send and receive data in valid JSON format. Avoid binary payloads.

{ "metric": "temperature", "value": 23.5, "timestamp": 1718000000 }

Start Building Real-time Applications

Take the leap from documentation to real code. Our WebSocket API makes it simple to add real-time features to your products.

Create Free Account