Socket
Socket
Sign inDemoInstall

json-rpc2.0-node

Package Overview
Dependencies
5
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    json-rpc2.0-node

A simple and extendable json-rpc-2.0 implementation, include server and client, written by typescript


Version published
Maintainers
1
Install size
503 kB
Created

Readme

Source

Client with http Trasport

import { createHttpRpcClient } from 'json-rpc2.0-node'
const client = createHttpRpcClient('http://endpoint',{Authorization:"token or other headers, or other http header"})
const res = await client.invoke('method','param1','param2')
client.notify('method','param1','param2')

// or cast to an interface
const t:T = client.as<T>()
t.method('param1','param2')

Client with custom Trasport

// implement the transport interface
// export interface Transport {
//     (payload: string): Promise<string | undefined>
// }

import { Client,Trasport } from 'json-rpc2.0-node'

function Mytransport(json:string){
    return Promise.resolve(/*json respose*/)
}

const client = new Client(Mytransport)

Server

import { Server } from 'json-rpc2.0-node'
const server = new Server()
server.expose('hello', () => 'hello world!')
const jsonbody = `
{
	"id":10,
	"method":"hello",
	"jsonrpc":"2.0"
}
`
const jsonrpcResponse = await server.handle(jsonbody)
// send your response back to client 

see more help in src/tests

Keywords

FAQs

Last updated on 04 Jul 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc