uwsgi-rpc
v0.1.1
Published
Call registered uWSGI RPC commands via node.
Downloads
10
Readme
uwsgi-rpc
uwsgi-rpc is not just a sexy name, but also an npm package for calling RPC functions registered in the uWSGI RPC stack.
Since I couldn't find a protocol specification, this code is basically one part translation of the uWSGI core written in C and one part reverse engineering of unbit's sample uWSGI RPC server written for node.
API
The package name is uwsgi-rpc, but the exported module is called RPCConnection
which is a much nicer name for constructors.
new RPCConnection(host, port)
Create a new object which we can use to call RPC functions at the specified host and port. For convenience, the connection is created lazily every time it is needed and therefore there is no net.Socket instance available on the object.
RPCConnection.prototype.call(functionName, args, callback)
Call an RPC function with the given name (as a string). The second parameter should be an array containing any arguments to the function. Since uWSGI handles all data as strings, every argument will be naively converted to a string. In other words, keep your data to primitive types. The third parameter is the callback which will be called with the result as a string.
Example
var RPCConnection = require('uwsgi-rpc');
var rpc = new RPCConnection('localhost', 3000);
rpc.call('getPrimes', [10, 20], function (response) {
console.log(response)
});
// OUTPUT: 11,13,17,19