@nodeguy/json-rpc
a simple JSON-RPC client
Last updated 3 years ago by nodeguy .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @nodeguy/json-rpc 
SYNC missed versions from official npm registry.

This is a JSON-RPC client library. It is compliant with the JSON-RPC 2.0 Specification.

Why?

I wrote yet another JSON-RPC library in JavaScript because the existing solutions I looked at tied themselves to a specific transport (e.g., HTTP) or were more complicated to use than just calling a function. RPC stands for Remote Procedure Call so it should be as simple to use as calling a procedure.

Usage

You set up the library by giving it a transport which is a function that takes an AsyncIterable and returns an AsyncIterable. This simple interface gives it the power to work with any underlying transport (e.g., HTTP, WebSocket, etc.). HTTP and WebSocket transports are provided.

Once initialized, it returns an object called methods that is an object representing the server. Calling a method on the server is as simple as calling the method on the methods object. All methods return promises.

Examples

HTTP

const assert = require('assert')
const jsonRpc = require('@nodeguy/json-rpc')
const url = require('url')

const transport = jsonRpc.transport(url.parse('http://www.example.com'))
const client = jsonRpc.client(transport)
const server = client.methods

server.subtract(42, 23).then((response) => {
  assert.equal(response, 19)
}

WebSocket

const assert = require('assert')
const jsonRpc = require('@nodeguy/json-rpc')
const url = require('url')

const transport = jsonRpc.transport(url.parse('ws://www.example.com'))
const client = jsonRpc.client(transport)
const server = client.methods

server.subtract(42, 23).then((response) => {
  assert.equal(response, 19)
}

Copyright

Copyright 2016 David Braun

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Current Tags

  • 0.3.2                                ...           latest (3 years ago)

8 Versions

  • 0.3.2                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (5)

Copyright 2014 - 2016 © taobao.org |