Nullifying Precipitation Machine

npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

wsrpc

1.3.0 • 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({
    port: 4242,
    service: proto.lookupService('MyService')
})
 
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

11

version

1.3.0

license

BSD-3-Clause

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability