JSPM

rpc-typescript

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q21610F
  • License MIT

An RCP library for TypeScript

Package Exports

  • rpc-typescript

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rpc-typescript) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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());