1.2.0 β€’ Published 1 year ago

jsonrpc4js v1.2.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 year ago

English | πŸ‡¨πŸ‡³ δΈ­ζ–‡

JSONRPC4JS

Documentation

Visit https://www.moonquakes.io/guide/javascript.html.

Quick Start

Installing

pnpm add jsonrpc4js

Server

const { NewServer } = require('jsonrpc4js')

class TcpRpc {
  add(a: number, b: number): number {
    return a + b
  }
}
const port = 3200
const server = NewServer('tcp', port) // Also support http protocol.
server.register(new TcpRpc())
server.start()

Client

const { NewClient } = require('jsonrpc4js')

const client = NewClient('TcpRpc', 'tcp', `localhost:3200`) // Also support http protocol.
let res = await client.call('add', 1, 2) // 3

Service registration & discovery

consul

const { Consul } = require('jsonrpc4js')

const discovery = new Consul('http://localhost:8500')

// Set discovery in server and client.
// const server = NewServer('tcp', port, discovery)
// const client = NewClient('TcpRpc', 'tcp', discovery)

nacos

const { Nacos } = require('jsonrpc4js')

const discovery = new Nacos('http://localhost:8848')

// Set discovery in server and client.
// const server = NewServer('tcp', port, discovery)
// const client = NewClient('TcpRpc', 'tcp', discovery)

Test

pnpm test

License

Apache-2.0 license

1.2.0

1 year ago

1.1.0

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago