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-basicVerified import paths — ran on the pinned version, not inferred.
Simple GET request with gzip and redirect handling, streaming response body.
Use res.body to read the stream instead of relying on a third callback argument.
Pass a custom cache object with get(url) and set(url, response) methods.
Always call .end() on the returned stream to complete the request.
Explicitly set duplex: true if you want to send a body with methods that normally don't have one.
Write any body data before calling .end() and avoid async operations between creating the request and ending it.
Use new URL('http://example.com?key=value').href to ensure proper encoding.Ensure you call req.end() on the returned stream. Check for err in callback.
Write all body data before calling .end(). Use .once('finish', ...) to know when the request completes.Pass a valid URL string starting with http:// or https://, e.g., 'http://example.com'.
Use const request = require('http-basic');