Logo image

Laralord WebSocket

Multi-tenant WebSocket solution with Pusher-like API

Laralord WebSocket is an open-source Laravel project providing a multi-tenant WebSocket solution with a Pusher-like API. Built on Laravel Reverb, it offers real-time communication and includes a CRUD API for application management. You can deploy it standalone—no need to install Reverb in your app. This project is part of the Laralord Project ecosystem.

LicenseLaravelPHPTestsDocker Image Version

Features

  • Multi-Tenancy: Isolate WebSocket connections and data for multiple tenants.
  • Pusher-Compatible API: Seamlessly integrate with Pusher clients for real-time messaging.
  • Laravel Reverb: Leverage Laravel’s native WebSocket server for performance and simplicity.
  • Application Management: CRUD API to create, read, update, and delete applications.
  • Open-Source: Free to use and contribute under the MIT license.

Requirements

  • PHP: 8.2 or higher
  • Laravel: 11.x
  • Composer: Required for dependency management
  • Database: PostgreSQL, Redis, or similar

Installation

  1. Clone the Repository:
    git clone https://github.com/laralord-project/websocket.git
    cd websocket
    Copy
  2. Create .env Files:
    cp .env.example .env
    # the env file below need to configure laralord server
    cp .env.server.example .env.server
    Copy
  3. Start Docker Containers:
    $ docker compose up -d websocket
    Copy

After the microservice is up and running, it exposes two ports (default IP is 10.5.0.1):

  • Port 8080: For WebSocket connections
  • Port 8000: For applications CRUD API

Application Management API

Base URL

http://localhost:8000/api

Authentication

All endpoints require Bearer token authentication:

Authorization: Bearer your_api_token_here

Routes

MethodEndpointController ActionDescription
GET/applicationsWebsocketAppController@indexList all applications
POST/applicationsWebsocketAppController@storeCreate a new application
GET/applications/{;application}WebsocketAppController@showRetrieve a specific application
PUT/PATCH/applications/{application}WebsocketAppController@updateUpdate a specific application
DELETE/applications/{application}WebsocketAppController@destroyDelete a specific application

Endpoints

1. List All Applications

GET /applications

Example Request:

curl -X GET http://localhost:8000/api/applications \
  -H "Authorization: Bearer your_api_token_here"

Example Response:

{
  "data": [
    {
      "id": "237467559627198718",
      "name": "test-app",
      "app_key": "w7YCZe2lYJulvSX1rWeyukBCcnlkCxlb",
      "app_secret": "7acxDi3qtGSRdPtJCp01uk8sqE6DXmiQ",
      "ping_interval": 60,
      "allowed_origins": ["*"],
      "max_message_size": 10000,
      "options": null,
      "created_at": "2025-04-16T06:51:18.000000Z",
      "updated_at": "2025-04-16T06:51:18.000000Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "total": 1,
    "per_page": 15
  },
  "status": "success"
}

2. Create Application

POST /applications

Parameters:

NameTypeRequiredDescription
namestringYesApplication name

Example Request:

curl -X POST http://localhost:8000/api/applications \
  -H "Authorization: Bearer your_api_token_here" \
  -H "Content-Type: application/json" \
  -d '{"name": "test-app"}'

Example Response:

{
    "data": {
      "id": "237467559627198718",
      "name": "test-app",
      "app_key": "w7YCZe2lYJulvSX1rWeyukBCcnlkCxlb",
      "app_secret": "7acxDi3qtGSRdPtJCp01uk8sqE6DXmiQ",
      "created_at": "2025-04-16T06:51:18.000000Z",
      "updated_at": "2025-04-16T06:51:18.000000Z"
   },
   "status": "success"
}

3. Get Application Details

GET /applications/{id}

Path Parameters:

NameTypeDescription
idstringApplication ID to retrieve

Example Request:

curl -X GET http://localhost:8000/api/applications/237467559627198718 \
  -H "Authorization: Bearer your_api_token_here" \
  -H "Accept: application/json"

Example Response:

{
    "data": {
      "id": "237467559627198718",
      "name": "test-app",
      "app_key": "w7YCZe2lYJulvSX1rWeyukBCcnlkCxlb",
      "app_secret": "7acxDi3qtGSRdPtJCp01uk8sqE6DXmiQ",
      "created_at": "2025-04-16T06:51:18.000000Z",
      "updated_at": "2025-04-16T06:51:18.000000Z"
   },
   "status": "success"
}

4. Delete Application

DELETE /applications/{id}

Path Parameters:

NameTypeDescription
idstringApplication ID to delete

Example Request:

curl -X GET http://localhost:8000/api/applications/237467559627198718 \
  -H "Authorization: Bearer your_api_token_here" \
  -H "Accept: application/json"

Example Response:

{
   "data": {
      "id": "237467559627198718",
      "name": "test-app",
      "app_key": "w7YCZe2lYJulvSX1rWeyukBCcnlkCxlb",
      "app_secret": "7acxDi3qtGSRdPtJCp01uk8sqE6DXmiQ",
      "created_at": "2025-04-16T06:51:18.000000Z",
      "updated_at": "2025-04-16T06:51:18.000000Z"
   },
   "status": "success"
}

Usages

1. Install the Required JavaScript Client

npm install laravel-echo pusher-js
Copy

GitHub Repository: Visit the Laralord Websocket GitHub repository for source code, issues, and contributions.

Licensing: Laralord Websocket is licensed under the MIT License. See the LICENSE file for details.

Laralord © 2024UI Build: 0.1.0-rc1-42-g4cde