Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anbang/json-rpc-client
JSON RPC
https://github.com/anbang/json-rpc-client
Last synced: about 8 hours ago
JSON representation
JSON RPC
- Host: GitHub
- URL: https://github.com/anbang/json-rpc-client
- Owner: anbang
- Created: 2019-11-08T08:45:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T09:17:15.000Z (about 5 years ago)
- Last Synced: 2024-10-13T19:18:27.429Z (about 1 month ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json-rpc-cli
这个package 是在 JSON RPC 的客户端中使用,传入您的`action`和对应参数即可在JS是获取到信息;
# Install
```
npm install json-rpc-cli --save
```# 使用方法演示
## then/catch
```
let rpc = require('json-rpc-cli');
const options = {
host: "127.0.0.1",
port: 8765
};
let client = new rpc.Client(options);function asyncfunc(opt) {
return new Promise((resolve, reject) => {
client.call(opt,
function (err, res) {
if (err) {
reject(err);
} else {
resolve(res)
}
}
);
})
}
console.log(' ------------- Start ------------- ')
let opt = {
"action": "account_create",
"password": '12345678'
};
asyncfunc(opt).then(data => {
console.log(' ------------- Success ------------- ')
console.log(data)
}).catch(err => {
console.log(' ------------- Error ------------- ')
console.log(err)
})```
## await/async
```
(async () => {
let rpc = require('json-rpc-cli');const options = {
host: "127.0.0.1",
port: 8765
};
let client = new rpc.Client(options);function asyncfunc(opt) {
return new Promise((resolve, reject) => {
client.call(opt,
function (err, res) {
if (err) {
reject(err);
} else {
resolve(res)
}
}
);
})
}
console.log(' ------------- Start ------------- ')
let opt = {
"action": "account_create",
"password": '12345678'
};
let res = await asyncfunc(opt);
console.log(res);
console.log(' ------------- End ------------- ')
})()
```