You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

json-rpc2.0-node

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

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

2.0.4
latest
npmnpm
Version published
Weekly downloads
6
-33.33%
Maintainers
1
Weekly downloads
 
Created
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

json-rpc

FAQs

Package last updated on 04 Jul 2018

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