Registry / http-networking / http-basic

http-basic

JSON →
library8.1.3jsnpmunverified

Low-level wrapper around Node.js http.request/https.request with built-in support for gzip/deflate, redirects, caching (memory/file), retries, and timeouts. Version 8.1.3 requires Node >=6.0.0. Includes TypeScript type definitions. Unlike higher-level libraries like `got` or `node-fetch`, this package provides a minimal, callback-based API that exposes raw streams and does not handle JSON parsing or body collection. The cache system supports Etag/Last-Modified validation and custom matchers. Maintained as a stable base for other packages.

npm install http-basic
INSTALL
IMPORT
SIG · HTTP-BASIC
H
http-basic
http-networkingjavascriptv8.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

request
const request = require('http-basic');
import request from 'http-basic';
Package does not export ESM. Only CommonJS via require().
HttpRequestOptions
import type { HttpRequestOptions } from 'http-basic';
TypeScript type import for options object. Available from v8.0.0+.
Response
import type { Response } from 'http-response-object';
import { Response } from 'http-basic';
Response type is re-exported by http-basic, but the canonical source is 'http-response-object'. Prefer importing from the latter for stability.

Simple GET request with gzip and redirect handling, streaming response body.

const request = require('http-basic'); request('GET', 'http://example.com', { followRedirects: true, gzip: true }, function (err, res) { if (err) { console.error('Request failed:', err); return; } console.log('Status:', res.statusCode); // Stream the body to stdout res.body.pipe(process.stdout); });
Debug
Known issues
breakingIn v8.0.0, the callback signature changed to (err, res) from (err, res, body). Body is no longer collected; you must handle the stream.
fix
Use res.body to read the stream instead of relying on a third callback argument.
affects: >=8.0.0
deprecatedThe 'cache' option with value 'memory' or 'file' uses bundled cache implementations that are deprecated in favor of custom cache objects implementing the ICache interface.
fix
Pass a custom cache object with get(url) and set(url, response) methods.
affects: >=8.0.0
gotchaCalling request() returns a WritableStream, but must still call .end() to send the request even if no body is written.
fix
Always call .end() on the returned stream to complete the request.
affects: >=6.0.0
breakingIn v7.0.0, the default value for the 'duplex' option changed. GET/HEAD/OPTIONS now default duplex: false, others default true.
fix
Explicitly set duplex: true if you want to send a body with methods that normally don't have one.
affects: >=7.0.0
gotchaThe request stream must be ended synchronously. If you attach data handlers to the returned stream, you must call .end() synchronously after the handler.
fix
Write any body data before calling .end() and avoid async operations between creating the request and ending it.
affects: >=6.0.0
deprecatedYou can no longer pass a string URL with query parameters; the library does not encode them. Use the URL constructor instead.
fix
Use new URL('http://example.com?key=value').href to ensure proper encoding.
affects: >=6.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'statusCode' of undefined
Callback not called due to request not being ended or network error not handled.
fix
Ensure you call req.end() on the returned stream. Check for err in callback.
Error: write after end
Attempting to write to the request stream after calling .end().
fix
Write all body data before calling .end(). Use .once('finish', ...) to know when the request completes.
RequestError: Invalid URI
URL is malformed or not fully qualified (must start with http:// or https://).
fix
Pass a valid URL string starting with http:// or https://, e.g., 'http://example.com'.
TypeError: request is not a function
import instead of require (package is CJS only).
fix
Use const request = require('http-basic');
Upgrade
Version history
8.1.3latest on npm
Audit
Dependencies
http-response-objectrequiredResponse object type and constructor used by http-basic
parse-cache-controlrequiredParses Cache-Control headers for cache logic
@types/nodeoptionalTypeScript types for Node.js built-in modules
Agent activity
23 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources