2.0.4 • Published 6 years ago
json-rpc2.0-node v2.0.4
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
2.0.4
6 years ago
2.0.3
6 years ago
2.0.2
6 years ago
2.0.1
6 years ago
2.0.0
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago
0.2.5
6 years ago
0.2.4
6 years ago
0.2.3
6 years ago
0.2.2
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago