0.1.0 • Published 3 years ago
rpc-typescript v0.1.0
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());
0.1.0
3 years ago