The LoopBack JSON-RPC Connector enables LoopBack applications to call JSON-RPC services.Note: This page was generated from the loopback-connector-jsonrpc/README.md.

LoopBack JSON-RPC Connector

The LoopBack JSON-RPC Connector allows you to call JSON-RPC services from LoopBack models. Ituses jayson as the client library.

Usage

  1. var ds = loopback.createDataSource({
  2. connector: require("loopback-connector-jsonrpc"),
  3. debug: false,
  4. baseURL: 'http://localhost:3000',
  5. operations: ['add', 'subtract']});
  6. var model = ds.createModel('dummy');
  7. model.add(1, 2, function(err, data) {
  8. console.log(err, data);
  9. });

Options to configure the connector:

  • url: Base URL to the json-rpc server
  • operations: An array of operation namesYou can also configure the baseURL as follows.
  1. {
  2. host: 'localhost',
  3. port: 3000
  4. }

Other properties will be passed to jayson.

  • reviver: Function to use as a JSON reviver
  • replacer: Function to use as a JSON replacer
  • generator: Function to generate request ids with. If omitted, Jayson will just generate a “random” number that is RFC4122compliant and looks similar to this: 3d4be346-b5bb-4e28-bc4a-0b721d4f9ef9
  • version: Can be either 1 or 2 depending on which specification should be followed in communicating with the server.Defaults to 2 for JSON-RPC 2.0
  • encoding: String that determines the encoding to use and defaults to utf8

License

MIT

Tags: connectorsreadme