Skip to content

vsDizzy/rpc-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpc-lib

Two-way RPC over websocket. The main goal is to expose entire interfaces not individual methods.

Usage:

import * as rpc from 'rpc-lib';

socket server

export class ServerApi {
  add(a: number, b: number) {
    return a + b;
  }

  sub(a: number, b: number) {
    return a - b;
  }
}
const rh = new rpc.Host(socket);
rh.addEndpoint('server-api', new ServerApi());

socket client

  const rh = new rpc.Host(socket);

  const serverApi = rh.getEndpoint<ServerApi>('server-api');
  console.log('1 + 2 =', await serverApi.add(1, 2));
  console.log('1 - 2 =', await serverApi.sub(1, 2));
});

About

Custom RPC library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published