# tiny-axios

> This is an http request plugin based on the axios package

Latest version **0.2.4** (published 2017-03-29) · MIT license · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2017-03-29 |
| First published | 2017-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Author | DengChao |
| Maintainers | dengchao2056 |
| Keywords | tiny-axios |

## Links

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

## Dependencies (2)

- [qs](https://npm.io/package/qs.md) ^6.4.0
- [axios](https://npm.io/package/axios.md) ^0.15.3

## Recent versions

- 0.2.4 (latest) — 2017-03-29
- 0.2.3 — 2017-03-29
- 0.2.2 — 2017-03-28
- 0.2.1 — 2017-03-24
- 0.2.0 — 2017-03-24
- 0.1.17 — 2017-03-23
- 0.1.16 — 2017-03-23
- 0.1.15 — 2017-03-23
- 0.1.14 — 2017-03-23
- 0.1.13 — 2017-03-23
- 0.1.12 — 2017-03-23
- 0.1.11 — 2017-03-16
- 0.1.10 — 2017-03-16
- 0.1.9 — 2017-03-15
- 0.1.8 — 2017-03-15
- … 8 more at https://npm.io/package/tiny-axios/versions

## README

```javascript
npm install --save tiny-axios
```

### Use
```javascript
// import tiny-axios
import { axios, axiosJson, axiosForm, axiosPullFile } from 'tiny-axios'
/**
 * axios, axiosJson, axiosForm, axiosPullFile:
 * axios(config, {loading, toast, responseRedirect, utils })
 * config [Object] axios 的请求参数
 *    config: {
 *      method: 'post',
 *      url: '',
 *      data: {}
 *    }
 * loading [Object] Loading handler, loading.open(), loading.close()
 * toast [Object] Toast handler, toast.open(), toast.success(), toast.error(), toast.warn()
 * responseRedirect [Array] [{code, handler()}]
 * utils: {
 *    'auth': {
 *    	// 特征码字段
 *    	code: 'code',
 *    	// 成功代号
 *    	num: 0,
 *    	// 失败提示字段
 *    	message: 'error',
 *      'defaultRequestCode': 'rq000',
 *      'defaultResponeCode': 'rs000',
 *    },
 *    'alert': {
 *       // timeout 连接超时
 *    	timeoutError: '连接超时，请重试',
 *    	otherError: '网络错误'
 *    }
 * }
 */

/**
 * axiosPullFile:
 * axiosPullFile({data = {}, url = '', method = 'post'})
 * data = post 请求参数
 * params: get 请求参数
 * url： 请求URL
 * method: 默认 post 方法
 */

// 简单的自定义封装
import { axios } from 'tiny-axios'
import Loading from 'tiny-loading'
import Tost from 'tiny-tost'
import Storage from 'storage-format'
let ajax = (config) => {
  return new Promise((resolve, reject) => {
    axios(config, {
      loading: Loading,
      toast: Tost,
      responseRedirect: {
        code: 202,
        handler() {
          console.log(202)
        }
      }
    })
    .then(res => {
      resolve(res)
    })
    .catch(err => {
      reject(err)
    })
  })
}
ajax.prototype.then = res => {}
ajax.prototype.catch = err => {}

export {
  ajax
}

// 使用
ajax({
  method: 'post',
  url: 'http://xxxxxx',
  data: {}
})
.then(res => {
  console.warn(res);
})
.catch(err => {
  console.error(err);
})
```

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