http(s) module with power.
npm install httpx --save
(async function () {
const response = await httpx.request('http://www.baidu.com/');
const body = await httpx.read(response, 'utf-8');
console.log(body);
})();
(async function () {
const response = await httpx.request('sse url');
for await (const event of httpx.readAsSSE(response)) {
console.log(event);
}
})();
httpx.request(url[, options])It returns Promise<Response>.
Requests the url with options, then return the response.
GET. Could be GET, POST, DELETE or PUT.RequestTimeout.false if you does not use agent.httpx.read(response[, encoding])It returns Promise<Buffer | String>.
Consume the response and read all data from the response.
httpx.readAsSSE(response)It returns AsyncGenerator<Event, void, unknown>.
Consume the response data with async iterator.
const { SocksProxyAgent } = require('socks-proxy-agent');
const httpx = require('httpx');
httpx.request('http://www.baidu.com/', {
// pass a http proxy agent
agent: new SocksProxyAgent('socks://your_proxy_server:3001')
});
The MIT license