@vmisztvl/tiny-rpc

Simple rpc with topics

Usage no npm install needed!

<script type="module">
  import vmisztvlTinyRpc from 'https://cdn.skypack.dev/@vmisztvl/tiny-rpc';
</script>

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.

Package repo

Full example

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.