@vmisztvl/tiny-rpc
v0.3.1
Published
Simple rpc with topics
Downloads
5
Readme
tiny-rpc
A node package that allows rpc over websockets and pushing messages from server to client.
- Focused on simplicity.
- Promise api.
- Written in typescript.
Server
import { RpcServer } from '@vmisztvl/tiny-rpc';
const rpc = new RpcServer(server, '/rpc');
rpc.registerHandler('getTime', () => Date.now());
rpc.onNewClient = (client) => client.post('messages', 'Hello client!');
Client
import { RpcClient } from '@vmisztvl/tiny-rpc';
const rpc = new RpcClient('/rpc');
rpc.subscribe('messages', addMessage);
button.onclick = async () => {
const data = await rpc.call('getTime');
console.log(data);
};
Please do submit feature requests / bugs / questions / suggestions.