{"id":18426,"library":"http-basic","title":"http-basic","description":"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.","status":"active","version":"8.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/ForbesLindesay/http-basic","tags":["javascript","http","https","request","fetch","gzip","deflate","redirect","cache","typescript"],"install":[{"cmd":"npm install http-basic","lang":"bash","label":"npm"},{"cmd":"yarn add http-basic","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-basic","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Response object type and constructor used by http-basic","package":"http-response-object","optional":false},{"reason":"Parses Cache-Control headers for cache logic","package":"parse-cache-control","optional":false},{"reason":"TypeScript types for Node.js built-in modules","package":"@types/node","optional":true}],"imports":[{"note":"Package does not export ESM. Only CommonJS via require().","wrong":"import request from 'http-basic';","symbol":"request","correct":"const request = require('http-basic');"},{"note":"TypeScript type import for options object. Available from v8.0.0+.","symbol":"HttpRequestOptions","correct":"import type { HttpRequestOptions } from 'http-basic';"},{"note":"Response type is re-exported by http-basic, but the canonical source is 'http-response-object'. Prefer importing from the latter for stability.","wrong":"import { Response } from 'http-basic';","symbol":"Response","correct":"import type { Response } from 'http-response-object';"}],"quickstart":{"code":"const request = require('http-basic');\n\nrequest('GET', 'http://example.com', { followRedirects: true, gzip: true }, function (err, res) {\n  if (err) {\n    console.error('Request failed:', err);\n    return;\n  }\n  console.log('Status:', res.statusCode);\n  // Stream the body to stdout\n  res.body.pipe(process.stdout);\n});","lang":"javascript","description":"Simple GET request with gzip and redirect handling, streaming response body."},"warnings":[{"fix":"Use res.body to read the stream instead of relying on a third callback argument.","message":"In v8.0.0, the callback signature changed to (err, res) from (err, res, body). Body is no longer collected; you must handle the stream.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Pass a custom cache object with get(url) and set(url, response) methods.","message":"The 'cache' option with value 'memory' or 'file' uses bundled cache implementations that are deprecated in favor of custom cache objects implementing the ICache interface.","severity":"deprecated","affected_versions":">=8.0.0"},{"fix":"Always call .end() on the returned stream to complete the request.","message":"Calling request() returns a WritableStream, but must still call .end() to send the request even if no body is written.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Explicitly set duplex: true if you want to send a body with methods that normally don't have one.","message":"In v7.0.0, the default value for the 'duplex' option changed. GET/HEAD/OPTIONS now default duplex: false, others default true.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Write any body data before calling .end() and avoid async operations between creating the request and ending it.","message":"The request stream must be ended synchronously. If you attach data handlers to the returned stream, you must call .end() synchronously after the handler.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Use new URL('http://example.com?key=value').href to ensure proper encoding.","message":"You can no longer pass a string URL with query parameters; the library does not encode them. Use the URL constructor instead.","severity":"deprecated","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure you call req.end() on the returned stream. Check for err in callback.","cause":"Callback not called due to request not being ended or network error not handled.","error":"TypeError: Cannot read property 'statusCode' of undefined"},{"fix":"Write all body data before calling .end(). Use .once('finish', ...) to know when the request completes.","cause":"Attempting to write to the request stream after calling .end().","error":"Error: write after end"},{"fix":"Pass a valid URL string starting with http:// or https://, e.g., 'http://example.com'.","cause":"URL is malformed or not fully qualified (must start with http:// or https://).","error":"RequestError: Invalid URI"},{"fix":"Use const request = require('http-basic');","cause":"import instead of require (package is CJS only).","error":"TypeError: request is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}