Tuesday 22 January 2019

Just RPC...

I've already posted this in my account but wanted to share here also.​📫 RpiecyI'm looking for feedback so any is apreciated! Even the bad stuff ;)​Hi there,I just wanted to share one of my latests libs with you guys, also another sideproject whom was born from a project at work and we decided to separate it.​It's a RPC Request/Response checker/generator wich tries to follow JSON-RPC 2.0 specification.It helps you with creating RPC Requests, Responses, Errors and Notifications with ease. It also checks they are valid.Also it has included a "cli comunicator", it sends and receives requests from stdin, but can be really easily changed!​You can find it here: https://github.com/nombrekeff/json-rpiecyHere is an example:const rpiecy = require('rpiecy'); const request1 = rpiecy.createRequest('method', { /* params */ }, 'id'); const request2 = rpiecy.createRequest({ method: 'method', params: {}, id: 'id' }); request1.print(); request2.output(); const response1 = rpiecy.createResponse('id', { /* result */ }); const response2 = rpiecy.createResponse({ result: { }, id: 'id' }); response1.print(); response2.output(); // Parse will return a Request, a Response or a Notification depending on what was parsed! const parsed = rpiecy.parse('{"method": "method", "id": "id", "jsonrpc": "2.0"}'); request1.sendAndAwait() .then(response => { console.log(`Response for ${request.id}: `, response); }) rpiecy.listen((request) => { console.log(`Received request ${request.id}: `, request); request.response({ data: SOME_DATA }).output(); });

Submitted January 22, 2019 at 12:28PM by nombrekeff

No comments:

Post a Comment