Options
All
  • Public
  • Public/Protected
  • All
Menu

wsrpc

wsrpc Build Status Coverage Status Package Version License

node.js/browser protobuf rpc over binary websockets.


Minimal example

my-service.proto

service MyService {
    rpc SayHello (HelloRequest) returns (HelloResponse) {}
}

message HelloRequest {
    required string name = 1;
}

message HelloResponse {
    required string text = 1;
}

server.js

const wsrpc = require('wsrpc')
const protobuf = require('protobufjs')

const proto = protobuf.loadSync('my-service.proto')

const server = new wsrpc.Server(proto.lookupService('MyService'), { port: 4242 })

server.implement('sayHello', async (request) => {
    return {text: `Hello ${ request.name }!`}
})

client.js

const wsrpc = require('wsrpc')
const protobuf = require('protobufjs')

const proto = protobuf.loadSync('my-service.proto')

const client = new wsrpc.Client('ws://localhost:4242', proto.lookupService('MyService'))

const response = await client.service.sayHello({name: 'world'})
console.log(response) // Hello world!

Generated using TypeDoc