Documentation Index Fetch the complete documentation index at: https://mintlify.com/slunghq/slung/llms.txt
Use this file to discover all available pages before exploring further.
The TypeScript client SDK provides a simple interface for sending events to Slung over WebSocket connections.
Installation
Install the SDK using npm:
npm install @slunghq/client
Quick Start
Connect to Slung and send events:
import { SlungClient } from "@slunghq/client" ;
const client = new SlungClient ( "ws://127.0.0.1:2077" );
await client . connect ();
client . sendEvent ({
value: 23.5 ,
timestamp: Date . now () * 1000 , // microseconds
series: "temp" ,
tags: [ "sensor=1" , "env=prod" ]
});
client . close ();
Simulated Streaming
For testing and development, use the built-in simulated stream:
import { SlungClient } from "@slunghq/client" ;
const client = new SlungClient ();
await client . connect ();
const stop = client . startSimulatedStream ({
intervalMs: 10 ,
initialValue: 90 ,
jitter: 1.2 ,
series: "temp" ,
tags: [ "sensor=1" , "env=dev" , "service=api" ]
});
// Stop the stream when done
process . on ( "SIGINT" , () => {
stop ();
client . close ( 1000 , "shutdown" );
process . exit ( 0 );
});
Types
SlungEvent
Represents a single event to send to Slung:
type SlungEvent = {
value : number ; // Numeric value
timestamp : number ; // Unix timestamp in microseconds
series : string ; // Series name
tags : string []; // Array of key=value tags
};
SimulatedStreamOptions
Configuration for simulated event streams:
type SimulatedStreamOptions = {
intervalMs ?: number ; // Milliseconds between events (default: 500)
initialValue ?: number ; // Starting value (default: 20)
jitter ?: number ; // Random variance magnitude (default: 0.5)
series ?: string ; // Series name (default: "temp")
tags ?: string []; // Tags array (default: ["sensor=1", "env=dev"])
};
Wire Protocol Utilities
The SDK exports low-level encoding functions for advanced use cases:
import {
createEventBinaryEncoder ,
encodeEventBinary ,
decodeEventBinary ,
nowUnixMicros
} from "@slunghq/client" ;
// Get current timestamp in microseconds
const timestamp = nowUnixMicros ();
// Encode a single event
const buffer = encodeEventBinary ({
timestamp ,
value: 42.0 ,
series: "cpu" ,
tags: [ "host=server1" ]
});
// Create a reusable encoder for a specific series
const encode = createEventBinaryEncoder ( "temp" , [ "sensor=1" ]);
const buf = encode ( timestamp , 23.5 );
// Decode binary event data
const event = decodeEventBinary ( buffer );
Next Steps
Client API Reference Detailed API documentation for SlungClient methods
Ingestion Guide Learn about event ingestion patterns