rpc-typescript

0.1.0 • Public • Published

rpc-typescript

[Work In Progress] An RPC library for TypeScript.

It's an annotation-based library for RPC with different transport protocols.

Supported transports are:

  • HTTP
  • Electron (host/renderer RPC)
  • Loopback

Syntax

The desired final work is like the following (still not implemented):

On server

@StubContract({
    transport: 'loopback'
})
export class LoopbackServer {

    @StubMethod()
    public async foo(): Promise<string> {
        return "Hello from foo";
    }
}

On client

@ProxyContract({
    transport: 'loopback'
})
export class LoopbackClient {

    @ProxyMethod()
    public foo(): Promise<string> {
        throw new RpcMethod('foo');
    }
}

// Somewhere else:
const client = ProxyContext.getChannel<LoopbackClient>(LoopbackClient); //or pass 'LoopbackClient'

const result = await client.foo();
expect(result)
    .toBe("Hello from foo");

HTTP

On the servers' side, while using the express, you should do this:

import { ExpressMiddleware } from 'rpc-typescript';

app.use(new ExpressMiddleware());

Package Sidebar

Install

npm i rpc-typescript

Weekly Downloads

5

Version

0.1.0

License

MIT

Unpacked Size

81.6 kB

Total Files

41

Last publish

Collaborators

  • amkherad