# @konghayao/request

> 同时支持 nodejs 和 browser

Latest version **1.5.5** (published 2021-12-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @konghayao/request
pnpm add @konghayao/request
yarn add @konghayao/request
bun add @konghayao/request
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.5 |
| Published | 2021-12-22 |
| First published | 2021-10-02 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 160.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | konghayao |

## Links

- npm: https://www.npmjs.com/package/@konghayao/request
- npm.io page: https://npm.io/package/@konghayao/request

## Dependencies (5)

- [qs](https://npm.io/package/qs.md) ^6.10.2
- [koa-router](https://npm.io/package/koa-router.md) ^10.1.1
- [node-fetch](https://npm.io/package/node-fetch.md) ^3.1.0
- [formdata-node](https://npm.io/package/formdata-node.md) ^4.3.1
- [@konghayao/rollup-plugin-conditional](https://npm.io/package/@konghayao/rollup-plugin-conditional.md) ^1.0.0

## Recent versions

- 1.5.5 (latest) — 2021-12-22
- 1.5.4 — 2021-12-15
- 1.5.3 — 2021-12-07
- 1.5.2 — 2021-11-26
- 1.5.1 — 2021-11-26
- 1.5.0 — 2021-11-19
- 1.4.1 — 2021-11-19
- 1.4.0 — 2021-10-18
- 1.3.0 — 2021-10-17
- 1.2.0 — 2021-10-17
- 1.1.0 — 2021-10-05
- 1.0.0 — 2021-10-02

## README

# request 模板请求函数

同时支持 nodejs 和 browser

## request 请求主函数的使用

```js
import {
    request,
    Transaction,
} from "https://cdn.jsdelivr.net/npm/@konghayao/request/dist/request.browser.js";
// import { request, Transaction } from "@konghayoa/request";
const root = "http://localhost:2021";

request({
    url: root + "/post/json",
    method: "post",
    headers: {}, // 请求头

    // get 请求的参数也是以对象格式统一写在 body 里面
    body: {
        a: 1,
        b: 2,
    },

    // string(default), json, binary,
    // 表示 body 使用什么格式进行传输，当为 get 请求时无效
    bodyType: "json",

    // json(default), text, arrayBuffer, buffer (nodejs), blob (browser)
    // 数据返回的时候以什么样的格式进行解析
    returnType: "json",
}).then((res) => {
    // res = { result, headers(nodejs), cookies(nodejs) }

    console.log(res);
});
```

## request 请求队列

```js
import { Transaction } from "https://cdn.jsdelivr.net/npm/@konghayao/promise-transaction@1.4.0/dist/promiseTransaction.esm.js";

// 传入请求的二维数组
const task = new Transaction([
    ["request1", () => request1({ url: "/" })],
    [
        "request2",
        (collection) => {
            // 在这个函数中可以通过
            console.log(collection["request1"]);
        },
    ],
]);

// 生成之后必须要手动启动队列
task.run();
```

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