1.0.1 • Published 6 years ago

lightrpc v1.0.1

Weekly downloads
13
License
MIT
Repository
github
Last release
6 years ago

LightRPC

Tiny JSON-RPC library - batteries not included.

build status npm version npm downloads

This project is not stable yet!

Getting Started

LightRPC is a minimal library for interacting with JSON RPC. It is designed to be small and work in browser and server.

Installing

Install using npm or yarn

npm install lightrpc
# or if you are using yarn
yarn add lightrpc

Obtain development copy

git clone https://github.com/Sekhmet/lightrpc.git
cd lightrpc
npm install

Usage

Usage in browser

<script src="https://unpkg.com/lightrpc/dist/lightrpc.min.js"></script>

Or if you want to use not minified version

<script src="https://unpkg.com/lightrpc/dist/lightrpc.js"></script>
// using UMD (browser)
const client = new window.LightRPC('https://api.steemit.com');

// using CommonJS
const Client = require('lightrpc');
const client = new Client('https://api.steemit.com');

// using ES6 modules
import Client from 'lightrpc';
const client = new Client('https://api.steemit.com');

// sending requests
client.call('get_accounts', [['sekhmet']], function(err, result) {
  if (err !== null) console.error(err);
  console.log('response', result);
});

const request = {
  method: 'get_accounts',
  params: [['sekhmet']],
};
client.send(request, function(err, result) {
  if (err !== null) console.error(err);
  console.log('response', result);
});

const requests = [
  {
    method: 'get_accounts',
    params: [['sekhmet']],
  },
  {
    method: 'get_dynamic_global_properties',
    params: [],
  },
];
client.sendBatch(requests, function(err, result) {
  if (err !== null) console.error(err);
  console.log('response', result);
});

Options

You can configure client by using optional options parameter to Client constructor.

const options = {
  timeout: 5000,
};

const client = new Client('https://api.steemit.com', options);

You can change some (or all) options for specific request using 3 parameter to send method.

OptionDefault valueDescription
timeout5000Time after request should timeout.
headers{'Content-Type': 'application/json'}Headers to be included in requests.

Running the tests

You can run lint and tests using npm script

npm run test

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

1.0.1

6 years ago

1.0.0-beta.5

6 years ago

1.0.0-beta.4

6 years ago

1.0.0-beta.3

6 years ago

1.0.0-beta.2

6 years ago

1.0.0-beta.1

6 years ago

1.0.0

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago