@omaksi/ts-rpc
v0.0.1
Published
ts-rpc is a simple RPC library written in TypeScript with support for sharing types between the client and server.
Downloads
2
Readme
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