# loadbalance-client

> An http client by request with loadbalance.

Latest version **0.2.2** (published 2019-05-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install loadbalance-client
pnpm add loadbalance-client
yarn add loadbalance-client
bun add loadbalance-client
```

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2019-05-11 |
| First published | 2017-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 37.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | miaowing |
| Maintainers | zfeng |
| Keywords | loadbalance, http-client |

## Links

- npm: https://www.npmjs.com/package/loadbalance-client
- Repository: https://github.com/miaowing/loadbalance-client
- Homepage: https://github.com/miaowing/loadbalance-client#readme
- Issues: https://github.com/miaowing/loadbalance-client/issues
- npm.io page: https://npm.io/package/loadbalance-client

## Dependencies (6)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [request](https://npm.io/package/request.md) ^2.81.0
- [uri-params](https://npm.io/package/uri-params.md) ^0.1.2
- [blueimp-md5](https://npm.io/package/blueimp-md5.md) ^2.7.0
- [loadbalance](https://npm.io/package/loadbalance.md) git+https://github.com/node-cloud/node-loadbalance.git
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.0

## Recent versions

- 0.2.2 (latest) — 2019-05-11
- 0.2.1 — 2019-05-11
- 0.2.0 — 2018-07-11
- 0.1.1 — 2017-12-11
- 0.1.0 — 2017-12-11
- 0.0.17 — 2017-05-02
- 0.0.16 — 2017-04-28
- 0.0.15 — 2017-04-28
- 0.0.14 — 2017-04-28
- 0.0.13 — 2017-04-27
- 0.0.12 — 2017-04-27
- 0.0.11 — 2017-04-26
- 0.0.10 — 2017-04-26
- 0.0.9 — 2017-04-26
- 0.0.8 — 2017-04-26
- … 7 more at https://npm.io/package/loadbalance-client/versions

## README

# loadbalance-client

## Usage
``` javascript
import LoadBalanceClient from 'loadbalance-client';
import Consul from 'consul';

const SERVICE_NAME = 'a-service';

const consul = new Consul(/* ignore */);
const lbClient = new LoadBalanceClient(SERVICE_NAME, consul);

export function getResource(id) {
    return lbClient.get({
        url: `/${SERVICE_NAME}/v1/resources/:id`,
        params: {id: id},
        headers: {
            'Content-Type': 'application/json'
        }
    });
}
```

## API

### new LoadBalanceClient(serviceName, consul, options)

#### serviceName

The service name.

#### consul

The consul client instance. you can see [node-consul](https://github.com/node-cloud/node-consul) for detail.

#### options

* strategy: Default is random. Others are 'round_robin_engine', 'priority_engine'.
* request: You can see [request](https://github.com/request/request) for detail.
* Other options you can see [node-consul](https://github.com/node-cloud/node-consul) for detail.

### lbClient.get(options)
### lbClient.post(options)
### lbClient.delete(options)
### lbClient.put(options)
### lbClient.send(options)

If you use send function, you must specific the options.method param. 
You can see [request](https://github.com/request/request) for detail.
This options have a higher priority than global options.

### lbClient.onPreSend(callback: request)
### lbClient.onPostSend(callback: response)

## Event
support events:

* refreshing-services


lbClient.on(eventName, callback);

lbClient.off(eventName, callback);

---
_Source: https://npm.io/package/loadbalance-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
