# fetch-request

> 基于fetch封装的ajax组件

Latest version **1.2.0** (published 2017-03-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install fetch-request
pnpm add fetch-request
yarn add fetch-request
bun add fetch-request
```

## 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.2.0 |
| Published | 2017-03-06 |
| First published | 2017-02-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.0.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | xyf1215 |
| Maintainers | xyf1215 |

## Links

- npm: https://www.npmjs.com/package/fetch-request
- Repository: https://github.com/xyf1215/fetch-request
- Homepage: https://github.com/xyf1215/fetch-request#readme
- Issues: https://github.com/xyf1215/fetch-request/issues
- npm.io page: https://npm.io/package/fetch-request

## Dependencies (1)

- [whatwg-fetch](https://npm.io/package/whatwg-fetch.md) ^2.0.2

## Recent versions

- 1.2.0 (latest) — 2017-03-06
- 1.1.0 — 2017-03-01
- 1.0.4 — 2017-03-01
- 1.0.3 — 2017-02-24
- 1.0.2 — 2017-02-24
- 1.0.1 — 2017-02-24
- 1.0.0 — 2017-02-24

## README

# fetch-request

> 基于fetch封装的ajax组件
使用application/x-www-form-urlencoded方式提交
## 使用
``````
import {setConfig, get, post, del, patch, put} from 'fetch-request'
setConfig({
  apiHost: 'http://www.baidu.com/',
  options: {
    credentials: 'include'
  },
  cache: true, //默认缓存
  headers: {
    Accept: 'application/json'
  },
  errHandle(err) {
    console.log(err)
  },
  reqHandle(url, options) {
    console.log(url, options)
  },
  respHandle(resp) {
    if (resp.errorCode === 200) {
      return resp.data
    } else {
      // 这里处理errorCode为其他的情况
      const error = new Error(resp.errorMessage || '未知错误')
      error.resp = resp
      throw error
    }
  }
})


get('user/info', {id: 123}).then(data => {
  console.log(data)
})
``````

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