EasyLayer Transport SDK
A lightweight SDK for easy client-side integration with EasyLayer-based applications. Provides a unified interface for sending requests and subscribing to events over different transport protocols (HTTP, IPC). Designed for seamless communication with our apps.
This document contains:
Setup
Make sure you have Node.js (version >= 16) installed.
Install the SDK via npm or yarn:
npm install @easylayer/transport-sdk
# or
yarn add @easylayer/transport-sdk
Basic Usage
import { Client } from '@easylayer/transport-sdk';
const client = new Client({
transport: {
type: 'http',
baseUrl: '`http://localhost:3000',`
},
});
const response = await client.request('query', 'generated_requestId', {
constructorName: 'Query_Name',
dto: {
modelIds: ['your_model_id'],
},
});
// Subscribe to events (if supported by transport)
const unsubscribe = client.subscribe('Your_Event_Name', async (event) => {
console.log('Received event:', event);
});
Transport API Reference
HTTP
Overview
HTTP transport is used for request-response communication with our apps.
All requests are sent as HTTP POST with a unified message envelope.
Configuration Example
const client = new Client({
transport: {
type: 'http',
baseUrl: '`http://localhost:3000'`
},
});
Message Format
All requests are sent as POST to the base URL with the following JSON body:
{
"action": "query",
"requestId": "generated_requestId",
"payload": {
"constructorName": "Query_Name",
"dto": {
"modelIds": ["your_model_id"]
}
}
}
Response Format
TODO
API Methods
client.request(action, requestId, payload)
— Send a request and await response.client.subscribe(constructorName, callback)
— Not supported for HTTP (will throw or be a no-op).
IPC (Node.js Child Process)
Overview
IPC transport is used for communication between Node.js processes (e.g., parent and child only).
Configuration Example
import { fork } from 'child_process';
const child = fork('path/to/easylayer_app');
const client = new Client({
transport: {
type: 'ipc',
child,
},
});
Message Format
Messages are sent as JSON objects:
{
"action": "query",
"requestId": "generated_requestId",
"payload": {
"constructorName": "Query_Name",
"dto": { "modelIds": ["your_model_id"] }
}
}
Response Format
{
"action": "queryResponse",
"requestId": "generated_requestId",
"payload": { /* response data */ }
}
API Methods
client.request(action, requestId, payload)
— Send a request and await response.client.subscribe(constructorName, callback)
— Subscribe to events of a given type (event-driven).
WebSocket (WS) (planned)
Not yet implemented in this SDK. Planned for future releases.
TCP (planned)
Not yet implemented in this SDK. Planned for future releases.