Node request util that supports request with basic or digest authentication.
$ npm install auth-request
- Support normal request, basic auth request, and digest auth request.
- Support both http and https
var request = require('auth-request');
var options = {
scheme: 'http',
hostname: 'localhost',
port: 8080,
path: '/path/to/resource',
method: 'POST',
data: { message: 'hello world' },
username: 'leo',
password: 'xxx'
};
request(options, function (err, result) {
if (err) return console.log(err);
console.log(result);
});
var request = require('auth-request');
This is the main function used to make http request, accepts an option and a callback.
A json object that may contain following fields.
URL resource scheme, support http or https, defaults to http.
Request host, defaults to 'localhost'.
Request port, defaults to 80 when http, or 443 when https.
Request path, defaults to '/'.
Request method, defaults to 'GET'.
Custom headers, optional, which will be appended to request headers.
Request data, if provided, data will be JSON-stringified to the request body, and content type will be set to 'application/json'.
Basic auth or digest auth username
Basic auth or digest auth password
Request callback function, called with error and result. The result object is of this structure { status: 200, data: ... }
.
There is a test server which you can use to test the correctness of an auth implementation.
- Support digest auth with full coverage.
- Refine code structure to support extension.
- Refine test cases.