# @nuskin/axios-util

> An Axios utility ...

Latest version **2.3.0** (published 2024-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nuskin/axios-util
pnpm add @nuskin/axios-util
yarn add @nuskin/axios-util
bun add @nuskin/axios-util
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2024-02-22 |
| First published | 2020-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ian Harisay |
| Maintainers | nkranendonk, emoore, nuskin-cws, klau, rellenberger |

## Links

- npm: https://www.npmjs.com/package/@nuskin/axios-util
- Repository: git@code.tls.nuskin.io:ns-am/utility/npm/axios-util
- Homepage: https://code.tls.nuskin.io/ns-am/utility/npm/axios-util/blob/master/README.md
- npm.io page: https://npm.io/package/@nuskin/axios-util

## Dependencies (2)

- [deepmerge](https://npm.io/package/deepmerge.md) 4.3.1
- [axios-retry](https://npm.io/package/axios-retry.md) 3.8.0

## Recent versions

- 2.3.0 (latest) — 2024-02-22
- 2.3.0-esm-cjs.1 (prerelease) — 2024-02-22
- 2.2.1 — 2024-02-02
- 2.2.1-cx15-6896.1 — 2024-01-22
- 2.2.0 — 2023-09-26
- 2.1.0 — 2023-05-19
- 2.0.0 — 2022-10-11
- 2.0.0-ngei-508.1 — 2022-10-11
- 1.0.2 — 2021-02-02
- 1.0.1 — 2020-05-21
- 1.0.1-add2readme.1 — 2020-05-21
- 1.0.0 — 2020-04-04

## README

# @nuskin/axios-util

`axios-util` enables you to utilize Axios as you normally would. By default, `axios-util` sets
the **timeout** to _10000ms_.

Retry functionality is implemented using the [axios-retry](https://www.npmjs.com/package/axios-retry) module. Utilize `getRetryAxiosInstance()` to obtain an Axios instance with retry capabilities. All default settings of `axios-retry` are applied, except for the *retryDelay*, which is set to *axiosRetry.exponentialDelay*. You can customize the retry behavior by supplying an `axios-retry` options object to `getRetryAxiosInstance()`.

## Installing

Using npm:

```bash
npm install @nuskin/axios-util
```

Using yarn:

```bash
yarn add @nuskin/axios-util
```

## Example usage

For ESM syntax, use `import`:
```js
import { axios, getRetryAxiosInstance } from '@nuskin/axios-util'
```

For CommonJS, use `require`:
```js
const { axios, getRetryAxiosInstance } = require('@nuskin/axios-util')
```

## Customizing Retry

To customize the retry logic, access `axios-retry` with ESM import syntax:

```js
let retryDelay = process.env.AXIOS_RETRY_DELAY || 5000
const myAxiosWithRetry = getRetryAxiosInstance({
    retries: 3,
    shouldResetTimeout: true,
    retryDelay: (retryCount) => {
        return retryCount * retryDelay
    },
    retryCondition: (error) => {
        // If retry condition is not specified, by default, idempotent requests are retried
        return error.response?.status >= 500 || error.code === 'ECONNABORTED'
    },
    onRetry: (retryCount, error, requestConfig) => {
        console.log(
            {
                retryCount,
                message: error.message,
                statusCode: error.response?.status,
                statusText: error.response?.statusText,
                responseData: error.response?.data
            },
            requestConfig.metric
        )
        return true;
    }
})
```

## Other Possibilities for axios-util
- Analytics
- Caching with [axios-cache-adapter](https://www.npmjs.com/package/axios-cache-adapter)
- Logging with [axios-logger](https://www.npmjs.com/package/axios-logger)

## License

[MIT](https://opensource.org/licenses/MIT)

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