Skip to content

Commit

Permalink
doc: improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Sep 19, 2023
1 parent aaf400f commit b40a596
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
httpx
===========
# httpx

http(s) module with power.

[![NPM version][npm-image]][npm-url]
Expand All @@ -17,7 +17,7 @@ http(s) module with power.
## Installation

```bash
$ npm install httpx --save
npm install httpx --save
```

## Usage
Expand Down Expand Up @@ -70,21 +70,25 @@ Or with `async/await`.

### `httpx.request(url[, options])`

Requests the url with options, then return the response.

- **url** String | Object - The URL to request, either a String or a Object that return by [url.parse](http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost).
- ***options*** Object - Optional
- ***method*** String - Request method, defaults to `GET`. Could be `GET`, `POST`, `DELETE` or `PUT`.
- ***data*** String | [Buffer](http://nodejs.org/api/buffer.html) | Readable - Manually set the content of payload.
- ***headers*** Object - Request headers.
- ***timeout*** Number - Request timeout in milliseconds. Defaults to 3000. When timeout happen, will return `RequestTimeout`.
- ***agent*** [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) - HTTP/HTTPS Agent object.
- ***method*** String - Request method, defaults to `GET`. Could be `GET`, `POST`, `DELETE` or `PUT`.
- ***data*** String | [Buffer](http://nodejs.org/api/buffer.html) | Readable - Manually set the content of payload.
- ***headers*** Object - Request headers.
- ***timeout*** Number - Request timeout in milliseconds. Defaults to 3000. When timeout happen, will return `RequestTimeout`.
- ***agent*** [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) - HTTP/HTTPS Agent object.
Set `false` if you does not use agent.
- ***beforeRequest*** Function - Before request hook, you can change every thing here.
- ***compression*** Boolean - Enable compression support. Tell server side responses compressed data
- ***beforeRequest*** Function - Before request hook, you can change every thing here.
- ***compression*** Boolean - Enable compression support. Tell server side responses compressed data

### `httpx.read(response[, encoding])`

Consume the response and read all data from the response.

- **response** Response - the Client response. Don't setEncoding() for the response.
- **encoding** String - Optional.
- **encoding** String - Optional. If specify the encoding, will return String. If not specify encoding, return the buffer.

## Using with http proxy

Expand All @@ -99,4 +103,5 @@ httpx.request('http://www.baidu.com/', {
```

## License

The MIT license

0 comments on commit b40a596

Please sign in to comment.