Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jayson

Package Overview
Dependencies
Maintainers
1
Versions
56
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.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
372K
decreased by-16.14%
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

FAQs

Package last updated on 22 Aug 2024

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc