3.0.1 • Published 24 days ago

httpx v3.0.1

Weekly downloads
7,293
License
MIT
Repository
github
Last release
24 days ago

httpx

http(s) module with power.

NPM version Node.js CI codecov npm download

Installation

npm install httpx --save

Usage

import * as httpx from 'httpx';

Request URL

const response = await httpx.request('http://www.baidu.com/');
const body = await httpx.read(response, 'utf-8');
console.log(body);

Request SSE URL

const response = await httpx.request('sse url');
for await (const event of httpx.readAsSSE(response)) {
  console.log(event);
}

API

httpx.request(url[, options])

It returns Promise<Response>.

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.
  • options Object - Optional
    • method String - Request method, defaults to GET. Could be GET, POST, DELETE or PUT.
    • data String | Buffer | 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/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

httpx.read(response[, encoding])

It returns Promise<Buffer | String>.

Consume the response and read all data from the response.

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

httpx.readAsSSE(response)

It returns AsyncGenerator<Event, void, unknown>.

Consume the response data with async iterator.

  • response Response - the Client response. Don't setEncoding() for the response.

Using with http proxy

import { SocksProxyAgent } from 'socks-proxy-agent';
import * as httpx from 'httpx';

await httpx.request('http://www.baidu.com/', {
  // pass a http proxy agent
  agent: new SocksProxyAgent('socks://your_proxy_server:3001')
});

License

The MIT license

sy-crafthifive-openapi@digitalcnzz/csbsdk@everything-registry/sub-chunk-1872@yungu-fed/yungu-api-gateway@wangsu_serverless/sharklet-cli@zalastax/nolb-httpx@zhike/co-wechat-api@zhaoyanxiang/co-wechat-api@zhennann/co-wechat-api@wbenxin/co-wechat-enterprise-api@ctsy/co-wechat-open-api@ikrong/co-wechat-apico-wxapp-open-apico-wechat-apico-wechat-api-cnnco-wechat-api-newco-wechat-oauthco-wechat-open-apico-open-wechat-apico-rongcloud-apico-alidayuco-easemob-apiegg-mifen-mqegg-mifen-mq-temp@alicloud/console-bench-coreapplet-api@alicloud/sso-cli@alicloud/tea-typescriptdtdream-aliware-csbeasy-weixin-oauth@jacksontian/dashscope@jacksontian/kimi@jacksontian/tiny-function@jinchaofs/clienthapi-wechathifive-openapi-nodejshifive-openapi-sdk-nodejs@laiye-ai/sdk-core@jonham/co-wechat-oauth@cuyl/wechat-enterprise-api@darabonba/typescriptdsalisdkdingrong_fc2dingbot@liyj1983/sharklet-cliesigntechegg-aliyun-api-gateway-fulles-wechat-open-apiesfchik-api-gateway-demohik-api-gateway-testoctokit.nodeots2pcloudpeer-wechat-apinode-hifive-openapinode-ebaasopen-weixin-apitdklabs_alicloud-fc2tyiot_gateway_sdksa-royd.ddnsrongcloud-sdk-es7ros-cdk-clisb-co-rongcloud-apiz_weappwxapp-open-apiwx-mini-thirdwx-third-open-apizd-co-wechat-apiwechat-platform-apiyp-co-open-wechat-apiyp-open-wechat-apiyp-wechat-apialiyun-api-gatewayaliware-csbaliyun-cs-node-sdkaliyun-oauthalicloud-log@winry/fc2@bilipay/openapi-core@forker/fc2@alicloud/http-core-sdk@alicloud/fc@alicloud/fc-builders@alicloud/fc2@alicloud/fun@alicloud/ros-cdk-cli@alicloud/log@alicloud/ots2@alicloud/mns@alicloud/oauth2@alicloud/pop-core@alicloud/credentialsartemis-http-client@aliyunmq/mq-http-sdkmessy-co-wechat-apimq-http-sdklppop@serverless-devs/credentials
3.0.1

24 days ago

3.0.0

24 days ago

2.3.2

2 months ago

2.3.1

5 months ago

2.3.0

7 months ago

2.2.7

3 years ago

2.2.6

4 years ago

2.2.5

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

5 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

8 years ago

1.0.0

9 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago