0.0.1 • Published 3 years ago

@omaksi/ts-rpc v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

ts-rpc

ts-rpc is a simple RPC library written in TypeScript with support for sharing types between the client and server.

yarn add ts-rpc

Usage

Configure RPC type:

type HelloWorldRPC = {
  method: 'hello'
  params: {
    world: string
  }
  result: {
    message: string
  }
}

Server (express middleware)

const rpcHandlerMiddleware = RpcHandlerMiddleware({
  hello: Handle<HelloWorldRPC> = (params) => ({ 
    message: `Hello ${params.world}` 
  })},
})

Client:

const result = await Call<HelloWorldRPC>('hello', { world: 'Neptune' })
console.log(result.message) // Hello Neptune

Example

See examples directory for full example.

License

MIT