node package manager

httpx

http(s) module with power

httpx

http(s) module with power.

$ npm install httpx --save
'use strict';
 
var httpx = require('httpx');
 
httpx.request('http://www.baidu.com/').then((response) => {
  response.pipe(process.stdout);
 
  response.on('end', () => {
    process.stdout.write('\n');
  });
}, (err) => {
  // on error 
});

Or co.

co(function* () {
  var response = yield httpx.request('http://www.baidu.com/');
 
  response.pipe(process.stdout);
 
  response.on('end', () => {
    process.stdout.write('\n');
  });
});

Or async/await.

(async function () {
  var response = await httpx.request('http://www.baidu.com/');
 
  response.pipe(process.stdout);
 
  response.on('end', () => {
    process.stdout.write('\n');
  });
})();
  • 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 - 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.
  • response Response - the Client response. Don't setEncoding() for the response.
  • encoding String - Optional.

The MIT license