https://github.com/bubao/self-promise-request
自己封装的一个request,使用promise,并能监听下载进度。
https://github.com/bubao/self-promise-request
Last synced: 12 months ago
JSON representation
自己封装的一个request,使用promise,并能监听下载进度。
- Host: GitHub
- URL: https://github.com/bubao/self-promise-request
- Owner: bubao
- Created: 2018-11-13T06:38:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-04T06:55:46.000Z (about 5 years ago)
- Last Synced: 2024-11-08T22:46:50.444Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# self-promise-request
自己封装的一个 request,使用 promise,并能监听下载进度。
## 安装
由于并没有 npmjs 的账号,所以只能通过 github 安装,使用 cnpm
```sh
$ cnpm i https://github.com/bubao/self-promise-request.git
# or
$ cnpm i https://github.com/bubao/self-promise-request.git#v0.0.3 --save
```
## 使用
基本用法。
```js
let Req = require("self-promise-request");
const Requests = new Req();
// 使用 on 函数监听进度
Requests.on("progress", res => {
console.log(res);
});
// request 直接能接收 key value 的参数,和 npm 的 request 模块接收的参数一致
Requests.request({ uri: "http://www.baidu.com" });
```
如果想下载文件到本地
```js
let Req = require("self-promise-request").Downloader;
const Requests = new Req();
// 使用 on 函数监听进度
Requests.on("progress", res => {
console.log(res);
});
// request 直接能接收 key value 的参数,和 npm 的 request 模块接收的参数一致
Requests.request({ uri: "http://www.baidu.com", pipe: "./1.html"});
```