httpx
http(s) module with power
Last updated 8 years ago by jacksontian .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install httpx 
SYNC missed versions from official npm registry.

httpx

http(s) module with power.

NPM version build status Coverage Status David deps npm download

Installation

$ npm install httpx --save

Usage

'use strict';

const 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 with co.

co(function* () {
  var response = yield httpx.request('http://www.baidu.com/');

  response.pipe(process.stdout);

  response.on('end', () => {
    process.stdout.write('\n');
  });
});

Or with async/await.

(async function () {
  var response = await httpx.request('http://www.baidu.com/');

  response.pipe(process.stdout);

  response.on('end', () => {
    process.stdout.write('\n');
  });
})();

API

httpx.request(url[, options])

  • 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])

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

License

The MIT license

Current Tags

  • 2.2.7                                ...           latest (5 years ago)

15 Versions

  • 2.2.7                                ...           5 years ago
  • 2.2.6                                ...           5 years ago
  • 2.2.5                                ...           5 years ago
  • 2.2.4                                ...           6 years ago
  • 2.2.3                                ...           6 years ago
  • 2.2.2                                ...           6 years ago
  • 2.2.1                                ...           6 years ago
  • 2.2.0                                ...           7 years ago
  • 2.1.4                                ...           8 years ago
  • 2.1.3                                ...           8 years ago
  • 2.1.2                                ...           9 years ago
  • 2.1.1                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 7
Dependencies (1)
Dev Dependencies (4)

Copyright 2013 - present © cnpmjs.org | Home |