Giter Site home page Giter Site logo

qertis / request-json-rpc2 Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 1.0 74 KB

Simplified JSON-RPC2 request client.

Home Page: https://www.npmjs.com/package/request-json-rpc2

License: MIT License

JavaScript 100.00%
json-rpc-api json-rpc-client json-rpc2 json-rpc2-client jsonrpc-client jsonrpc2 rpc

request-json-rpc2's Introduction

Request JSON-RPC 2 - Simplified JSON-RPC 2.0 NodeJS client

Super simple to use

Request JSON-RPC 2 is designed to be the simplest way possible to make JSON-RPC 2 calls.

const requestJsonRpc2 = require('request-json-rpc2');

const result = await requestJsonRpc2({
  url: '/api',
  body: {
    method: 1,
    params: 'hello world',
  },
});

Powerful sample

const result = await requestJsonRpc2({
  url: '/api',
  body: {
    id: '1234567890',
    method: 'record',
    params: {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "$id": "https://example.com/employee.schema.json",
      "title": "Record of employee",
      "description": "This document records the details of an employee",
      "type": "object",
      "properties": {
        "id": {
          "description": "A unique identifier for an employee",
          "type": "number",
        },
      },
    },
  },
  headers: {
    'Accept': 'application/schema+json',
  },
});

HTTP Authentication

Includes basic or bearer.

const result = await requestJsonRpc2({
  url: '/api',
  body: {
    method: 1,
    params: 'auth hello world',
  }, 
  auth: {
    'user': 'username',
    'pass': 'password',
    'sendImmediately': false,
  },
});

JWT

JSON Web Token example.

const result = await requestJsonRpc2({
  url: '/api',
  body: {
    method: 1,
    params: 'JWT hello world',
  }, 
  jwt: 'ewogICJhbGciOiAiSFMyNTYiLAogICJ0eXAiOiAiSldUIgp9.ewogICJuYW1lIjogIlJlcXVlc3QgSlNPTi1SUEMgMi4wIgp9',
});

Signature

Ed25519Signature2018 example.

const result = await requestJsonRpc2({
  url: '/api',
  body: {
    method: 1,
    params: 'signature hello world',
  },
  signature: {
    "@context": ["https://w3id.org/security/v2"],
    "id": "did:example:123456789abcdefghi#keys-1",
    "type": "Ed25519VerificationKey2018",
    "controller": "did:example:123456789abcdefghi",
    "expires": "2023-01-08T16:02:20Z",
    "publicKeyBase58": "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
  },
});

Testing

See tests directory.

request-json-rpc2's People

Contributors

qertis avatar

Stargazers

 avatar

Forkers

baskovsky

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.