Skip to content

API reference / @chanx-js/client

chanx ​

Type-safe WebSocket client for chanx AsyncAPI schemas, with topic multiplexing. Zero dependencies, with optional bindings for React, Vue, Svelte and Solid, and first-class support for plain JavaScript and Node.

Documentation · Getting started · API reference

bash
pnpm add @chanx-js/client
pnpm add -D @chanx-js/codegen
npx @chanx-js/codegen http://localhost:8000/asyncapi.json -o src/generated
ts
import { createClient } from '@chanx-js/client';
import { chat } from './generated';

const client = createClient({ baseUrl: 'wss://api.example.com' });
const connection = client.connect(chat, { params: { room: 'lobby' } });

connection.on('chat_notification', (message) => console.log(message.payload.message));
connection.send({ action: 'chat', payload: { message: 'hello' } });
ImportFor
@chanx-js/clientThe runtime: clients, connections, topics
@chanx-js/client/reactuseChannel, useTopics
@chanx-js/client/vueComposables returning refs
@chanx-js/client/svelteStores, for Svelte 4 and 5
@chanx-js/client/solidSignals and accessors

MIT licensed.

Modules ​

MIT licensed