Home

Awesome

http-basic

Simple wrapper arround http.request/https.request

Build Status Dependency Status NPM version

Installation

npm install http-basic

Usage

var request = require('http-basic');

var options = {followRedirects: true, gzip: true, cache: 'memory'};

var req = request('GET', 'http://example.com', options, function (err, res) {
  if (err) throw err;
  console.dir(res.statusCode);
  res.body.resume();
});
req.end();

method:

The http method (e.g. GET, POST, PUT, DELETE etc.)

url:

The url as a string (e.g. http://example.com). It must be fully qualified and either http or https.

options:

callback:

The callback is called with err as the first argument and res as the second argument. res is an http-response-object. It has the following properties:

returns:

If the method is GET, DELETE or HEAD, it returns undefined.

Otherwise, it returns a writable stream for the body of the request.

Implementing a Cache

A Cache is an object with three methods:

A cached response object is an object with the following properties:

getResponse should call the callback with an optional error and either null or a cached response object, depending on whether the url can be found in the cache. Only GETs are cached.

setResponse should just swallow any errors it has (or resport them using console.warn).

invalidateResponse should call the callback with an optional error if it is unable to invalidate a response.

A cache may also define any of the methods from lib/cache-utils.js to override behaviour for what gets cached. It is currently still only possible to cache "get" requests, although this could be changed.

License

MIT