Socket
Book a DemoInstallSign in
Socket

node-jsonrpc-client

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-jsonrpc-client

A lightweight JSON-RPC 2.0 client

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
199
-69.8%
Maintainers
1
Weekly downloads
 
Created
Source

node-jsonrpc-client npm version

A really, really simple JSON-RPC 2.0 client.

Installation

npm install --save node-jsonrpc-client
# Or
yarn add node-jsonrpc-client

Usage

Simple usage

const { JsonRpc } = require("node-jsonrpc-client");

// Our API server is at http://example.org/api
const client = new JsonRpc("http://example.org/api");
// Let's call the 'saySomething' method that takes two parameters, 'to' and 'message'
client.call("saySomething", { to: "Alice", message: "Hi, Bob!" })
  .then((result) => {
    // The 'saySomething' method has a field 'output'
    console.log("output", result.output);
  })
  .catch((err) => {
    // oops, something went wrong!
    console.error("Oops! Error code " + err.code + ": " + err.message);
  });

Using cookies

If the API is using a cookie to keep track of the session, you can use setUseCookies(true):

const { JsonRpc } = require("node-jsonrpc-client");
const CookieJar = require('tough-cookie')

const cookieJar = new CookieJar()

// Our API server is at http://example.org/api
const client = new JsonRpc("http://example.org/api");
// Let's call the 'login' method that takes two parameters, 'username' and 'password'
client.call("login", { username: "alice", password: "monkey" }, cookieJar)
  .then((loginResult) => {
    // The 'getMessages' method has a field 'messages' and requires the cookie from login
    client.call("getMessages", {}, cookieJar).then((msgResult) => {
      console.log("Messages: ", result.messages);
    });
  })
  .catch((err) => {
    // oops, something went wrong!
    console.error("Oops! Error code " + err.code + ": " + err.message);
  });

Keywords

jsonrpc

FAQs

Package last updated on 11 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.