# feaxios

> Tiny Fetch wrapper that provides a similar API to Axios

Latest version **0.0.23** (published 2024-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install feaxios
pnpm add feaxios
yarn add feaxios
bun add feaxios
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.0.23 |
| Published | 2024-10-18 |
| First published | 2024-02-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 55.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Maintainers | divyamsingh234 |
| Keywords | axios, fetch |

## Links

- npm: https://www.npmjs.com/package/feaxios
- Repository: https://github.com/divyam234/feaxios
- Issues: https://github.com/divyam234/feaxios/issues
- npm.io page: https://npm.io/package/feaxios

## Dependencies (1)

- [is-retry-allowed](https://npm.io/package/is-retry-allowed.md) ^3.0.0

## 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.23 (latest) — 2024-10-18
- 0.0.22 — 2024-10-06
- 0.0.21 — 2024-10-06
- 0.0.20 — 2024-07-31
- 0.0.19 — 2024-07-31
- 0.0.18 — 2024-06-30
- 0.0.17 — 2024-04-04
- 0.0.16 — 2024-04-04
- 0.0.15 — 2024-04-01
- 0.0.14 — 2024-04-01
- 0.0.13 — 2024-03-21
- 0.0.12 — 2024-03-02
- 0.0.11 — 2024-02-28
- 0.0.10 — 2024-02-22
- 0.0.9 — 2024-02-21
- … 8 more at https://npm.io/package/feaxios/versions

## README

# feaxios

`feaxios` is a lightweight alternative to **Axios**, providing the same familiar API with a significantly reduced footprint of **2KB**. It leverages the native `fetch()` API supported in all modern browsers, delivering a performant and minimalistic solution. This makes it an ideal choice for projects where minimizing bundle size is a priority.

### Key Features

- **Lightweight:** With a size of less than 1/5th of Axios, `feaxios` is an efficient choice for projects with strict size constraints.

- **Native Fetch API:** Utilizes the browser's native fetch, ensuring broad compatibility and seamless integration with modern web development tools.

- **Interceptor Support:** `feaxios` supports interceptors, allowing you to customize and augment the request and response handling process.

- **Timeouts:** Easily configure timeouts for requests, ensuring your application remains responsive and resilient.

- **Retries:** Axios retry package is integrated with feaxios.


### When to Use feaxios

While [Axios] remains an excellent module, `feaxios` provides a compelling option in scenarios where minimizing dependencies is crucial. By offering a similar API to Axios, `feaxios` bridges the gap between Axios and the native `fetch()` API.

```sh
npm install feaxios
```

**_Request Config_**

```ts
{

url: '/user',

method: 'get', // default

baseURL: 'https://some-domain.com/api/',

transformRequest: [function (data, headers) {
  return data;
}],

transformResponse: [function (data) {

    return data;
}],

headers: {'test': 'test'},

params: {
    ID: 12345
},

 paramsSerializer: {

    encode?: (param: string): string => {},

    serialize?: (params: Record<string, any>, options?: ParamsSerializerOptions ),

    indexes: false
  },

  data: {},

  timeout: 1000, // default is 0ms

  withCredentials: false,

  responseType: 'json', // default

  validateStatus: function (status) {
    return status >= 200 && status < 300;
  },

  signal: new AbortController().signal,

  fetchOptions:  {
     redirect: "follow"
  },
 retry: { retries: 3 }
```

**In fetchOptions you can pass custom options like proxy , agents etc supported on nodejs**

### Usage

```js
import axios from "feaxios";

axios
  .get("https://api.example.com/data")
  .then((response) => {
    // Handle the response
    console.log(response.data);
  })
  .catch((error) => {
    // Handle errors
    console.error(error);
  });
```

**_With Interceptors_**

```js
import axios from "feaxios";

axios.interceptors.request.use((config) => {
  config.headers.set("Authorization", "Bearer *");
  return config;
});
axios.interceptors.response.use(
  function (response) {
    return response;
  },
  function (error) {
    //do something with error
    return Promise.reject(error);
  },
);
```
**Axios Retry Package is also ported to feaxios**

```ts
import axios from "feaxios"
import axiosRetry from "feaxios/retry"

const http = axios.create({
  timeout: 3 * 1000 * 60,
})

axiosRetry(http, { retryDelay: axiosRetry.exponentialDelay })
```
Visit: https://github.com/softonic/axios-retry to see more options.

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