2023-10-30 17:34:06 +08:00
|
|
|
|
|
|
|
![downloads](https://img.shields.io/npm/dt/@gm5/request.svg)
|
|
|
|
![version](https://img.shields.io/npm/v/@gm5/request.svg)
|
2020-09-16 20:07:28 +08:00
|
|
|
|
2020-09-20 16:40:29 +08:00
|
|
|
# @gm5/equest
|
|
|
|
> 对Http的request进一步封装, 提供常用的API.
|
2020-09-16 20:07:28 +08:00
|
|
|
|
|
|
|
## Install
|
|
|
|
|
|
|
|
```bash
|
2020-09-20 16:40:29 +08:00
|
|
|
npm i @gm5/request
|
2020-09-16 20:07:28 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```javascript
|
2020-09-20 16:40:29 +08:00
|
|
|
import Request from '@gm5/request'
|
|
|
|
import http from 'http'
|
2020-09-16 20:07:28 +08:00
|
|
|
|
|
|
|
http
|
|
|
|
.createServer((req, res) => {
|
|
|
|
let request = new Request(req, res)
|
|
|
|
|
|
|
|
// print the fixed url
|
|
|
|
console.log(request.url)
|
|
|
|
|
2023-10-30 17:34:06 +08:00
|
|
|
request.ip // get client ip address
|
2020-09-16 20:07:28 +08:00
|
|
|
|
|
|
|
// http://test.com/?foo=bar
|
2023-10-30 17:34:06 +08:00
|
|
|
request.query['foo'] // bar
|
2020-09-16 20:07:28 +08:00
|
|
|
})
|
|
|
|
.listen(3000)
|
|
|
|
```
|