karmia-rpc
v0.3.1
Published
Karmia RPC module.
Downloads
2
Readme
karmia-rpc
RPC module of Karmia JavaScript library
Installation
npm install karmia-rpc
Example
const karmia_rpc = require('karmia-rpc'),
methods = new karmia_rpc();
Define method
Key-Value style
methods.set('method_name', function () {
});
Object style
const methods_object = {
method_namespace: {
method_name: function () {
}
},
method_other_namespace: {
method_name: function () {
}
},
method_name: function () {
}
}
methods.set(methods_object);
Get method
// Top level
methods.get('method_name');
// Lower level
methods.get('method_namespace.method_name');
Clear methods
methods.clear();
Call method
Single request
const karmia_context = require('karmia-context'),
context = karmia_context(),
request = {
method: 'method_name',
params: {
argument_1: 'value1',
argument_2: 'value2'
}
};
const promise = methods.call(context, request);
Batch request
const karmia_context = require('karmia-context'),
context = karmia_context(),
requests = [
{
method: 'method_name',
params: {
argument_1: 'value1',
argument_2: 'value2'
}
}, {
method: 'method_namespace.method_name'
}
];
const promise_array = methods.call(context, requests);