HTTP/HTTPS Request Wrapper

1.0.0 · abandoned · verified Tue Apr 21

The `http-https` package, at its sole stable version `1.0.0`, is a minimal wrapper designed to simplify making HTTP or HTTPS requests in Node.js. It automatically selects the appropriate native module (`http` or `https`) based on the protocol found in the target URL, exposing a unified `request` method similar to `http.request`. This package was published over a decade ago (around 2012) by Isaac Schlueter and has seen no updates, new features, or bug fixes since its initial release. Consequently, it is an abandoned project and is not actively maintained. While it streamlined basic outbound web requests in older Node.js environments, modern applications should consider actively maintained alternatives that offer current best practices, better error handling, and broader feature sets.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates making both HTTP and HTTPS requests using the `http-https` wrapper, showing how it automatically handles protocol selection, and illustrating its compatibility with both URL strings and parsed URL objects (using Node's built-in `url` module).

const hh = require('http-https');
const url = require('url'); // Node.js built-in url module

// Example 1: Direct URL string
const simpleReq = hh.request('http://example.com/bar', (res) => {
  console.log(`HTTP Status: ${res.statusCode}`);
  res.setEncoding('utf8');
  let rawData = '';
  res.on('data', (chunk) => { rawData += chunk; });
  res.on('end', () => {
    console.log('Simple HTTP Response received.');
  });
});
simpleReq.on('error', (e) => console.error(`Simple request error: ${e.message}`));
simpleReq.end();

// Example 2: With parsed URL object and custom headers
const someUrlMaybeHttpMaybeHttps = 'https://secure.example.com/foo';
const parsedOpt = url.parse(someUrlMaybeHttpMaybeHttps);
parsedOpt.headers = {
  'User-Agent': 'flergy mc flerg/1.0'
};
parsedOpt.method = 'GET'; // Changed to GET for typical fetch

const secureReq = hh.request(parsedOpt, (res) => {
  console.log(`HTTPS Status: ${res.statusCode}, Headers: ${JSON.stringify(res.headers)}`);
  res.setEncoding('utf8');
  let rawData = '';
  res.on('data', (chunk) => { rawData += chunk; });
  res.on('end', () => {
    console.log('Secure HTTPS Response received.');
  });
});
secureReq.on('error', (e) => console.error(`Secure request error: ${e.message}`));
secureReq.end();

view raw JSON →