UNPKG

rpc-typescript

Version:
57 lines (45 loc) 1.16 kB
# 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 ```javascript @StubContract({ transport: 'loopback' }) export class LoopbackServer { @StubMethod() public async foo(): Promise<string> { return "Hello from foo"; } } ``` ### On client ```javascript @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: ```javascript import { ExpressMiddleware } from 'rpc-typescript'; app.use(new ExpressMiddleware()); ```