# jsreq

> An easy and simple Node.js HTTP client.

Latest version **2.0.0** (published 2020-04-04) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2020-04-04 |
| First published | 2020-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lai Yiming |
| Maintainers | inlym |
| Keywords | HTTP, request, http, https, node, client, inlym |

## Links

- npm: https://www.npmjs.com/package/jsreq
- npm.io page: https://npm.io/package/jsreq

## 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) — 2020-04-04
- 1.2.1 — 2020-04-02
- 1.2.0 — 2020-04-02
- 1.0.1 — 2020-03-30
- 1.0.0 — 2020-03-30
- 0.0.1 — 2020-03-27

## README

# jsreq
一个简单易用的Node.js HTTP请求客户端，支持Promise。


## 安装
使用NPM安装
```shell
$ npm install jsreq
```

使用CNPM安装
```shell
$ cnpm install jsreq
```


## 使用
首先引用
```js
const jsreq = require('jsreq');
```

支持多种调用方式，返回一个Promise。


```js
let url = 'http://www.example.com'
let options = {
    baseURL:'http://www.example.com',
    url:'/abc',
    path:'/path/to?name=inlym'
    method:'POST',
    data:'I am data',
    headers:{
        aaa:'aaa',
        bbb:'bbb'
    },
    responseType:'text'
}
jsreq(url,options).then(console.log).catch(console.log)  // 方式一

jsreq(url).then(console.log).catch(console.log)  // 方式二

jsreq(options).then(console.log).catch(console.log)  // 方式三
```

## 请求参数
对于url，你可以单独拿出来放在参数的第1项，也可以放在 options 参数中。

其中 options 支持以下参数
```js
let options = {
    baseURL:'http://www.example.com',
    url:'https://www.example.com',
    uri:'https://www.example.com',  // url的别名
    path:'/path/to?name=inlym',
    query:{                         // query对象
        age:19,
        isGood:true
    },
    method:'POST',
    data:'I am data',
    headers:{
        aaa:'aaa',
        bbb:'bbb'
    },
    responseType:'text'
}
```

## 响应
响应是一个对象，包含以下属性：

1. statusCode
2. statusMessage
3. headers
4. data

例如
```js
{
    statusCode:200,
    statusMessage:'OK',
    headers:{
        'date': 'Mon, 30 Mar 2020 14:13:26 GMT',
        'content-type': 'application/json; charset=utf-8',
        'content-length': '1179',
    },
    data:'I am response data'
}
```

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