# foraxios

> Easy Axios to use.

Latest version **1.0.5** (published 2023-07-22) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2023-07-22 |
| First published | 2023-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 59.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | requesttimeout |
| Keywords | axios, easy-axios, foraxios |

## Links

- npm: https://www.npmjs.com/package/foraxios
- Repository: https://github.com/z41z/foraxios
- Homepage: https://github.com/z41z/foraxios#readme
- Issues: https://github.com/z41z/foraxios/issues
- npm.io page: https://npm.io/package/foraxios

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.4.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2023-07-22
- 1.0.4 — 2023-07-22
- 1.0.3 — 2023-07-22
- 1.0.2 — 2023-07-22
- 1.0.1 — 2023-07-22

## README

# foraxios
Easy Axios to use.
## Install

``` node
  npm i foraxios //or yarn add foraxios
```

### Usage

``` js
import ForAxios from 'foraxios';
// Message is unnecessary
import { Message } from 'element-ui';
const foraxios = new ForAxios({
  // Request handler
  request(config) {
    // config content is api request content.
    if (config.isOpenApi === undefined) {
      config.headers = {
        'token': `Bearer ${localStorage.access_token}`
      }
    }
  },
  // Request success handler
  success(res) {
    // res is api data returned
    if (res.code !== 0) {
      Message.error(res.msg)
    }
    return {
      ...res,
      isSuccess: true
    }
  },
  // Request error handler
  error(err) {
    Message.error(err)
    return err
  }
})

// Common request
const login = (data) => {
  return foraxios.$api(
    {
      url: `/api/login`,
      method: 'post',
      data,
      name: '用户登录'
    }
  )
}
// Donwload binary file
const exportFile = (data) => {
  return foraxios.$api(
    {
      url: `/api/export`,
      data: {
        ...data,
        fileName: 'export.xlsx'
      },
      name: 'export file',
      type: 'file'
    }
  )
}
```


### Base Config `Object`
  - {Function} request = (config) => { } :`Request handler.`
  - {Function} success = (res) => { } :`Request success handler.`
  - {Function} error = (err) => { } :`Request error handler.`
  - {Number} timeout = 10e3 :`Request timeout.`
  - {Object} headers  :`Request.`
  - {Boolean} isShowConsole = true :`Is show message on console.`

### Request API Config `Object`
  - {String} url  :`Request url.`
  - {*} data  :`Request data.`
  - {String} name  :`API name.`
  - {String} method = 'get' :`Request method.`
  - {String} type  :`Set value 'file' then download binary file.`
  - {*} mockData  :`Mock Data`

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