Giter Site home page Giter Site logo

node-json-rpc2's Introduction

node-json-rpc2

A small and easy to use JSON-RPC 2.0 for node.js.

Specifications

Based on the 2.0 (revised) specifications. See here More information here

Usage

Server :

Protocol supported : http
Method supported : POST, GET

const RpcServer = require('node-json-rpc2').Server;
const server = new RpcServer({
    protocol:'http',
    path:'/',
    port:80,
    method:'GET'
});
server.addMethod('add', function(parameters, id){
    return {id:id, error:null, result:parameters[0]+parameters[1]}
});

Client :

Protocol supported : http, https
Method supported : POST, GET

const RpcClient = require('../lib/index').Client;
var client = new RpcClient({
    protocol:'http',//Optional. Will be http by default
    path:'/',
    port:80,
    method:'GET'
});
client.call({
    method:'add',//Mandatory
    params:[1,2],//Will be [] by default
},(err, res)=>{
    if(err){
        console.log(err);
        //Do something
    }
    console.log('Data:',res);//Json parsed.
});

Usage with bitcoind

This is an exemple usage to connect to bitcoind using json rpc

'use strict';
const RpcClient = require('node-json-rpc2');
const config = {
    protocol:'http',//Optional. Will be http by default
    host:'127.0.0.1',//Will be 127.0.0.1 by default
    user:'bitcoin',//Optional, only if auth needed
    password:'local321',//Optional. Can be named 'pass'. Mandatory if user is passed.
    port:9998,//Will be 8443 for https or 8080 for http by default
    method:'POST'//Optional. POST by default
};
var client = new RpcClient(config);
client.call({
    method:'getinfo',//Mandatory
    params:[],//Will be [] by default
    id:'rpcExample',//Optional. By default it's a random id
    jsonrpc:'2.0'//Optional. By default it's 2.0
},(err, res)=>{
    if(err){
       //Do something
    }
    console.log('Data:',res);//Json parsed.
});

node-json-rpc2's People

Contributors

alex-werner avatar bob620 avatar

Watchers

 avatar  avatar

Forkers

ko-matsu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.