Need private packages and team management tools?Check out npm Teams »

wsrpc

1.4.1 • Public • Published

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!

Install

npm i wsrpc

DownloadsWeekly Downloads

2

Version

1.4.1

License

BSD-3-Clause

Unpacked Size

188 kB

Total Files

26

Last publish

Collaborators

  • avatar