http-ext
the http request client for nodejs module
Install
You can install http-ext using the Node Package Manager (npm):
$ npm install --save http-ext
Simple Usage
var httpExt = ; httpExt;
How to use
- httpExt.get(url, [options], callback)
- httpExt.post(url, [options], callback)
- httpExt.put(url, [options], callback)
- httpExt.delete(url, [options], callback)
- Sending a custom body
- Using a http(s) proxy
### httpExt.get(url, [options], callback)
Arguments
- url: The url to connect to. Can be http or https.
- options: (all are optional) The following options can be passed:
- parameters: an object of query parameters
- headers: an object of headers
- cookies: an array of cookies
- allowRedirects: (default: true , only with httpExt.get() ), if true, redirects will be followed
- maxRedirects: (default: 10 ). For example 1 redirect will allow for one normal request and 1 extra redirected request.
- timeout: (default: none ). Adds a timeout to the http(s) request. Should be in milliseconds.
- proxy, if you want to pass your request through a http(s) proxy server:
- host: eg: "192.168.0.1"
- port: eg: 8888
- protocol: (default: 'http' ) can be 'http' or 'https'
- rejectUnauthorized: validate certificate for request with HTTPS. More here
- callback(err, res): A callback function which is called when the request is complete. res contains and response ( res ) the body ( res.body )
Example without options
var httpExt = ; httpExt;
Example with options
var httpExt = ; httpExt;
### httpExt.post(url, [options], callback)
Arguments
- url: The url to connect to. Can be http or https.
- options: (all are optional) The following options can be passed:
- parameters: an object of post parameters (content-type is set to application/x-www-form-urlencoded; charset=UTF-8)
- json: if you want to send json directly (content-type is set to application/json)
- body: custom body content you want to send. If used, previous options will be ignored and your custom body will be sent. (content-type will not be set)
- headers: an object of headers
- cookies: an array of cookies
- allowRedirects: (default: false ), if true, redirects will be followed
- maxRedirects: (default: 10 ). For example 1 redirect will allow for one normal request and 1 extra redirected request.
- timeout: (default: none). Adds a timeout to the http(s) request. Should be in milliseconds.
- proxy, if you want to pass your request through a http(s) proxy server:
- host: eg: "192.168.0.1"
- port: eg: 8888
- protocol: (default: 'http' ) can be 'http' or 'https'
- rejectUnauthorized: validate certificate for request with HTTPS. More here
- callback(err, res): A callback function which is called when the request is complete. res contains the response ( res ) and the body ( res.body )
Example without extra options
var httpExt = ; httpExt;
Example with options
var httpExt = ; httpExt;
### httpExt.put(url, [options], callback)
Same options as httpExt.post(url, [options], callback)
### httpExt.delete(url, [options], callback)
Same options as httpExt.post(url, [options], callback)
### Sending a custom body Use the body option to send a custom body (eg. an xml post)
Example
var httpExt = ; httpExt;
### Using a http(s) proxy
Example
var httpExt = ; httpExt;
API
(Coming soon)
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using gulp.
License
Copyright (c) 2015 liuxiong. Licensed under the MIT license.