🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

jayson

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jayson

JSON-RPC 1.0/2.0 compliant server and client

4.2.0
latest
Source
npm
Version published
Weekly downloads
595K
-17.05%
Maintainers
1
Weekly downloads
 
Created

What is jayson?

The 'jayson' npm package is a JSON-RPC 2.0/1.0 compliant server and client library for Node.js. It allows you to create JSON-RPC servers and clients, making it easy to implement remote procedure calls (RPC) in a standardized way.

What are jayson's main functionalities?

Creating a JSON-RPC Server

This code creates a JSON-RPC server with a single method 'add' that takes two arguments and returns their sum. The server listens on port 3000.

const jayson = require('jayson');

const server = jayson.server({
  add: function(args, callback) {
    callback(null, args[0] + args[1]);
  }
});

server.http().listen(3000);

Creating a JSON-RPC Client

This code creates a JSON-RPC client that connects to a server running on 'http://localhost:3000'. It makes a request to the 'add' method with arguments [1, 1] and logs the result.

const jayson = require('jayson');

const client = jayson.client.http('http://localhost:3000');

client.request('add', [1, 1], function(err, response) {
  if(err) throw err;
  console.log(response.result); // 2
});

Batch Requests

This code demonstrates how to make batch requests using the JSON-RPC client. It sends two 'add' requests in a single batch and logs the responses.

const jayson = require('jayson');

const client = jayson.client.http('http://localhost:3000');

const batch = [
  client.request('add', [1, 1], null, false),
  client.request('add', [2, 2], null, false)
];

client.request(batch, function(err, responses) {
  if(err) throw err;
  console.log(responses); // [{jsonrpc: '2.0', result: 2, id: 1}, {jsonrpc: '2.0', result: 4, id: 2}]
});

Other packages similar to jayson

Keywords

jsonrpc

FAQs

Package last updated on 19 Apr 2025

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