0.0.1 • Published 4 years ago
@omaksi/ts-rpc v0.0.1
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-rpcUsage
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 NeptuneExample
See examples directory for full example.
License
MIT
0.0.1
4 years ago