RPC JSON - Stream transform protocol
RPC JSON - Server and Client Stream with JSON header and RAW body
$ npm install rpc-json
Run tests
Browse module (e.g. node_modules/rpc-json
) install directory, and run tests:
$ npm test# or $ node test.js
Compare test results with travis run tests.
Include in your script
const rpc = ;
query
function
Define custom server async { console; // response back to client return await ;}
Simple client-server stream pipe
const server = query; // using custom 'query' request functionconst client = ; // pipe: client (request to:) > server (response back to:) > clientclient;
exec
calls
Promise clientcatchconsoleerror; /* Output---------client-request head1 body1log1 { head: 's-head1', body: <Buffer 62 6f 64 79 31> }client-request head2 body2log2 { head: 's-head2', body: <Buffer 62 6f 64 79 32> }client-request head3 body3log3 { head: 's-head3', body: <Buffer 62 6f 64 79 33> }*/
exec
calls
async/await async { const r1 = await client; console; const r2 = await client; console; const r3 = await client; console;}; /* Output---------client-request head1 body1log1 { head: 's-head1', body: <Buffer 62 6f 64 79 31> }client-request head2 body2log2 { head: 's-head2', body: <Buffer 62 6f 64 79 32> }client-request head3 body3log3 { head: 's-head3', body: <Buffer 62 6f 64 79 33> }*/
Simple client-server socket stream pipe
const net = ; const srv = net; /* Output---------log { head: 'head', body: <Buffer 62 6f 64 79> }socket server closesocket client end*/
request (<Promise> response, head, body)
Server async function head
- Value, can be any type (not a function) - deserialized with JSONbody
- Buffer or Stringthis
- Bind Server Object- return -
<Promise> response (head, body)
- callback server response
Default server anonymous async request
function will response back to client with the same request head
and body
values, like this: async (response, head, body) => await response(head, body)
exec (head, body)
Client Promise function head
- Value, can be any type (not a function)body
- Buffer or Stringthis
- Bind Client Object- return -
Promise.resolve( { head, body } )
-body
is Buffer
Custom stream error event names
serverError
- error event name forrpc.server
clientError
- error event name forrpc.client
server;client;
For more info consult or run the test.js file.
RPC JSON is licensed under the MIT license. See the included LICENSE
file for more details.