# orcrist-request

> SPCARE App Http Request

Latest version **2.0.0** (published 2021-02-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install orcrist-request
pnpm add orcrist-request
yarn add orcrist-request
bun add orcrist-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 | 2.0.0 |
| Published | 2021-02-03 |
| First published | 2019-12-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 50.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | shangboyang |
| Maintainers | cindytuo, npmzr, shangboyang |
| Keywords | request, fetch |

## Links

- npm: https://www.npmjs.com/package/orcrist-request
- Repository: https://git.medbanks.cn:62113/spcare-public/orcrist-request
- npm.io page: https://npm.io/package/orcrist-request

## 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

- 2.0.0 (latest) — 2021-02-03
- 1.9.0 — 2021-01-20
- 1.8.1 — 2021-01-15
- 1.8.0 — 2021-01-15
- 1.7.2 — 2020-12-17
- 1.7.1 — 2020-12-17
- 1.7.0 — 2020-12-17
- 1.6.1 — 2020-06-22
- 1.6.0 — 2020-06-17
- 1.5.1 — 2020-05-29
- 1.5.0 — 2020-05-28
- 1.4.0 — 2020-04-29
- 1.3.2 — 2020-04-20
- 1.3.1 — 2020-04-20
- 1.2.1 — 2020-02-28
- … 7 more at https://npm.io/package/orcrist-request/versions

## README

# orcrist request Ajax 请求功能组件

## Update Log

- v1.9.x 添加 FormData 文件上传兼容处理
- v1.8.x 添加默认请求 30s 熔断功能
- v1.5.x 添加接口 500 异常处理

## Install

> npm install --save orcrist-request

## Usage

Default JSON Content-Type: application/json

```js
import request from "orcrist-request";
// GET
const reqPromise = request("http://www.test.com/api/citys", {
  method: "get", // post 兼容大小写
  body: {
    foo: "bar",
  }, // Body数据部分会自动拼接至URL后
});

// POST
const req2Promise = request("http://www.test.com/api/citys", {
  method: "POST", // post 兼容大小写
  body: {
    foo: "bar",
  },
});

reqPromise.then((data) => data).catch((error) => console.error(error));
reqPromise2.then((data) => data).catch((error) => console.error(error));
```

FormData ver. (文件上传)

```js
// POST
const formReqPromise = request("http://www.test.com/api/fileUpload", {
  method: "POST", // post 兼容大小写
  type: "FORM", // form 兼容大小写
  body: {
    files: {}, // dom -> files[0]
  }, // formData.append('files', {})
});

formReqPromise.then((data) => data).catch((error) => console.error(error));
```

## API

|  参数  | 说明     |  类型  | 默认值                          |
| :----: | :------- | :----: | :------------------------------ |
|  url   | 请求 URL | String | 无                              |
| option | 操作     | Object | [Option Object](#option-object) |
| handle | 控制     | Object | [Handle Object](#handle-object) |

#### Option Object

|  参数   | 说明                     |  类型  | 默认值 | 可选值          |
| :-----: | :----------------------- | :----: | :----- | --------------- |
| method  | 请求方法类型             | String | 'get'  | 'get' / 'post'  |
|  type   | 发送数据类型             | String | 'json' | 'json' / 'form' |
| headers | 自定义请求 Header 头信息 | Object | 略     |
|  body   | 请求发送数据             | Object | 略     |

#### Handle Object

|  参数   | 说明                          |  类型  | 默认值 |
| :-----: | :---------------------------- | :----: | :----- |
| timeout | 请求 API 熔断超时限制，单位秒 | Number | 30     |

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