# @springworks/api-client

> Module for sending requests to other APIs through a circuit breaker

Latest version **3005.505.0** (published 2026-05-29) · 0 weekly downloads

## Install

```sh
npm install @springworks/api-client
pnpm add @springworks/api-client
yarn add @springworks/api-client
bun add @springworks/api-client
```

## Health

**Score 50/100 (C)** — status: active.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3005.505.0 |
| Published | 2026-05-29 |
| First published | 2015-08-19 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 7 |
| Unpacked size | 156 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | springworksprime, springworksdev |

## Links

- npm: https://www.npmjs.com/package/@springworks/api-client
- Repository: https://github.com/Springworks/m2h-mono
- Homepage: https://github.com/Springworks/m2h-mono/tree/master/packages/api-client#readme
- npm.io page: https://npm.io/package/@springworks/api-client

## Dependencies (7)

- [undici](https://npm.io/package/undici.md) ^6.21.1
- [@springworks/scrubber](https://npm.io/package/@springworks/scrubber.md) 3005.505.0
- [@springworks/http-status](https://npm.io/package/@springworks/http-status.md) 3005.464.1
- [@springworks/error-factory](https://npm.io/package/@springworks/error-factory.md) 3005.464.1
- [@springworks/input-validator](https://npm.io/package/@springworks/input-validator.md) 3005.464.1
- [@springworks/logger-interfaces](https://npm.io/package/@springworks/logger-interfaces.md) 3005.464.1
- [@springworks/circuit-breaker-factory](https://npm.io/package/@springworks/circuit-breaker-factory.md) 3005.464.1

## Recent versions

- 3005.505.0 (latest) — 2026-05-29
- 3005.499.2 — 2026-05-08
- 3005.485.1 — 2026-04-08
- 3005.464.1 — 2025-11-14
- 3005.458.0 — 2025-09-05
- 3005.456.0 — 2025-08-13
- 3005.455.1 — 2025-08-13
- 3005.454.1 — 2025-08-04
- 3005.450.0 — 2025-07-03
- 3005.449.0 — 2025-07-02
- 3005.434.0 — 2025-05-13
- 3005.433.0 — 2025-05-05
- 3005.424.2 — 2025-03-25
- 3005.418.0 — 2025-01-23
- 3005.383.0 — 2024-10-09
- … 565 more at https://npm.io/package/@springworks/api-client/versions

## README

# `@springworks/api-client`

Module for sending requests to other APIs through a circuit breaker created by [@springworks/circuit-breaker-factory](https://www.npmjs.com/package/@springworks/circuit-breaker-factory).

```sh
yarn add @springworks/api-client
```

## API

### `createClient(params)`

Creates a _api client_ using the provided config. Returns an object that exposes a `sendRequest(opts, expected_status_codes)` function that returns a _Promise_.

#### `params`

| Name                    | Type   | Description                                                                                                                                                                                                   | Required |
| ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| base_url                | String | Fully qualified uri string used as the base url                                                                                                                                                               | Yes      |
| circuit_breaker_config  | Object | Optional. The circuit breaker config. Please refer to [this](https://www.npmjs.com/package/@springworks/circuit-breaker-factory) documentation for details.                                                   | Yes      |
| logger                  | Logger | See [`@springworks/logger-interfaces`](https://github.com/Springworks/m2h-mono/tree/master/packages/logger-interfaces)                                                                                        | Yes      |
| auth                    | Object | An object with `username` and `password`.                                                                                                                                                                     | No       |
| opt_options             | Object |                                                                                                                                                                                                               | No       |
| opt_options.opt_auth    | Object | Optional authentication object that will be used for all requests sent towards the provided `base_url`. If there is an auth property in the `options` send in `sendRequest` then `opt_auth` gets overwritten. | No       |
| opt_options.opt_timeout | Number | Timeout (millis) used in all request from created client.                                                                                                                                                     | No       |

### `sendRequest(options, expected_status_codes)`

Sends the request based on the provided options and returns a resolved/rejected _Promise_.

**Options**

| Parameter    | Description                              | Type   | Required |
| ------------ | ---------------------------------------- | ------ | -------- |
| endpoint_uri | URI of the endpoint that's to be reached | string | Yes      |

**expected_status_codes**

| Type  | Description                                           | Entries Type | Entries Range | Required |
| ----- | ----------------------------------------------------- | ------------ | ------------- | -------- |
| Array | Expected status codes by the invoker of this function | Number       | [100, 500)    | Yes      |

**Example Usage**

```js
var api_client_factory = require('@springworks/api-client');

var config = {
  source_name: 'my-api',
  target_name: 'facebook-graph-api',
  window_duration: 1000, // optional
  num_buckets: 10, // optional
  timeout_duration: 3000, // optional
  error_threshold: 50, // optional
  volume_threshold: 5, // optional
};

var api_client = api_client_factory.createClient({
  base_url: 'http://api.machinetohuman.com',
  circuit_breaker_config: config,
  logger: logger,
});

var options = {
  endpoint_uri: '/vehicles/1234',
  // other request options
};

var expected_status_codes = [200];

api_client
  .sendRequest(options, expected_status_codes)
  .then(function (response_body) {
    // do your thing;
  })
  .catch(function (err) {
    // err.code is the statusCode of the response or 417 (if responded with code < 400)
  });
```

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