# axios-batch

> Axios batch calls, with return object for tracking

Latest version **0.0.8** (published 2022-06-23) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install axios-batch
pnpm add axios-batch
yarn add axios-batch
bun add axios-batch
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2022-06-23 |
| First published | 2021-02-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 27.8 KB |
| Known vulnerabilities | 0 (+24 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Paul van Woensel |
| Maintainers | dutchrican |
| Keywords | axios, parallel, retry, batch, requests |

## Links

- npm: https://www.npmjs.com/package/axios-batch
- Repository: https://github.com/DutchRican/axios-batch
- Homepage: https://github.com/DutchRican/axios-batch#readme
- Issues: https://github.com/DutchRican/axios-batch/issues
- npm.io page: https://npm.io/package/axios-batch

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [axios](https://npm.io/package/axios.md) ^0.27.2
- [axios-retry](https://npm.io/package/axios-retry.md) ^3.1.9

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2022-06-23
- 0.0.7 — 2021-02-05
- 0.0.6 — 2021-02-05
- 0.0.5 — 2021-02-03

## README

[![Build Status](https://travis-ci.com/DutchRican/axios-batch.svg?branch=master)](https://travis-ci.com/DutchRican/axios-batch)
[![Coverage Status](https://coveralls.io/repos/github/DutchRican/axios-batch/badge.svg?branch=master)](https://coveralls.io/github/DutchRican/axios-batch?branch=master)

# Axios-Batch

install to your project with:  
`npm i axios-batch`

## Examples

Instantiation without existing axios client:  
```
import { AxiosBatch } from 'axios-batch';

const ab = new AxiosBatch({ baseURL: 'https://yourEndPoint.com' });

// urls can be an array of strings or objects {url: "/posts/1", id: "myposts" };  
const requests = [{url: "/posts/1, id:"first-id"}, {url: "/posts/2", id:"other-id"}];  
const res = await ab.axiosBatch({ urls: requests });
```

Instantiation with existing axios client:  
```
import { AxiosBatch } from 'axios-batch';
import axios from 'axios';

const client = axios.create({ baseURL: 'https://yourEndPoint.com' });

const ab = new AxiosBatch({ client });

// urls can be an array of strings or objects {url: "/posts/1", id: "myposts" };  
const requests = [{url: "/posts/1, id:"first-id"}, {url: "/posts/2", id:"other-id"}];  
const res = await ab.axiosBatch({ urls: requests });
```

The returned object has the structure of `{allSuccess, allErrors}`  

allSuccess is an array with the structure of:   
```
[{data: <data-structure returned by api>, id:<id>}]
```

allErrors is an array with the structure of:  
```
[{error: <error status>, id: <id>}]
```

## Retry conditions

If a requests receives a status code of `[408, 500, 502, 504, 522 or 524]` upto 3 retries are attempted while increasing the backoff time.

### Options

AxiosBatch Class parameters:  
| Name                | Optional | default Value          |
|---------------------|----------|------------------------|
| client              | yes      | new axios instance     |
| headers             | yes      | empty object           |
| baseURL             | yes      | undefined              |
| backoffInterval     | yes      | 300 ms                 |
| degradationMax      | yes      | 6 consecutive failures |
| isDegradationSafety | yes      | false                  |

<hr />

axiosBatch function parameters
| Name             |  Optional | default Value |
|------------------|-----------|---------------|
| urls             | no        | none          |
| parallelRequests | yes       | 5             |
| batchDelayInMs   | yes       | 250ms         |
| headers          | yes       | empty object  |
| verbose          | yes       | false         |


-----
### issues

### using Create-React-App  

`npm i url` and adding a polyfill to either your webpack.config.js or react-app-rewired will fix *Can't resolve 'url' in ..* errors
```
fallback: {
        "url": require.resolve("url/")
      },
```

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