{"id":17387,"library":"tinyreq","title":"Tinyreq HTTP(s) Requests","description":"Tinyreq is a minimalist JavaScript library designed for making HTTP and HTTPS requests, aiming for simplicity and a small footprint. Currently at version 3.4.3, it offers both traditional callback-based and modern Promise-based APIs for handling responses. Its release cadence is generally conservative, with updates focusing on maintenance tasks such as documentation improvements, minor dependency upgrades (e.g., `follow-redirects`), and occasional bug fixes (e.g., addressing Promise handling in 3.2.5). A key differentiating factor is its commitment to being a \"tiny\" utility, providing core request functionality without the extensive feature sets found in larger HTTP clients, making it suitable for environments where bundle size and minimal dependencies are crucial.","status":"maintenance","version":"3.4.3","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/IonicaBizau/tinyreq","tags":["javascript","tinyreq","http","https","requests"],"install":[{"cmd":"npm install tinyreq","lang":"bash","label":"npm"},{"cmd":"yarn add tinyreq","lang":"bash","label":"yarn"},{"cmd":"pnpm add tinyreq","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for handling HTTP redirects, as indicated by version upgrade notes.","package":"follow-redirects","optional":false}],"imports":[{"note":"This package is primarily designed for CommonJS environments, and `require()` is the canonical import method.","symbol":"tinyreq","correct":"const tinyreq = require('tinyreq');"},{"note":"For ESM environments, use a default import. Named imports are not provided, and direct ESM module support might vary based on your bundler's CJS-to-ESM interop.","wrong":"import { tinyreq } from 'tinyreq';","symbol":"tinyreq","correct":"import tinyreq from 'tinyreq';"}],"quickstart":{"code":"const tinyreq = require(\"tinyreq\");\n\n// Make a basic GET request with a callback\ntinyreq(\"http://example.com/\", (err, body) => {\n    if (err) {\n        console.error(\"Callback GET error:\", err);\n        return;\n    }\n    console.log(\"Callback GET response body (first 100 chars):\");\n    console.log(body.substring(0, 100) + '...');\n});\n\n// Make a GET request with custom headers using Promises\ntinyreq({\n    url: \"http://example.com/\"\n  , headers: {\n        \"User-Agent\": \"Tinyreq-App/1.0\"\n    }\n}).then(body => {\n    console.log(\"Promise GET response body (first 100 chars):\");\n    console.log(body.substring(0, 100) + '...');\n}).catch(err => {\n    console.error(\"Promise GET error:\", err);\n});\n\n// Make a POST request with data to a test endpoint\ntinyreq({\n    url: \"https://httpbin.org/post\"\n  , method: \"POST\"\n  , data: {\n        message: \"Hello from tinyreq\",\n        timestamp: new Date().toISOString()\n    }\n}, (err, body) => {\n    if (err) {\n        console.error(\"Callback POST error:\", err);\n        return;\n    }\n    console.log(\"Callback POST response:\", JSON.parse(body).json);\n});","lang":"javascript","description":"Demonstrates making basic GET requests using both callback and Promise patterns, and a POST request with data to an external endpoint."},"warnings":[{"fix":"Upgrade to `tinyreq` version 3.2.5 or higher to ensure correct Promise behavior for accessing response bodies.","message":"Prior to version 3.2.5, using `tinyreq` with Promises (via `.then()`) might not correctly store or return the response body unless a callback was also provided. This was a significant bug affecting Promise-based usage.","severity":"breaking","affected_versions":"<3.2.5"},{"fix":"Use `import tinyreq from 'tinyreq';` for ESM, and ensure your build setup correctly handles CommonJS modules. Avoid `import { tinyreq } from 'tinyreq';`.","message":"The library's primary examples and typical usage patterns are geared towards CommonJS (`require`). While it generally interoperates with ESM via default imports, direct ESM module exports or named exports are not explicitly provided, which might require bundler configurations in strict ESM environments.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always check both `err` and `body` in callbacks, and utilize `.catch()` for Promise-based requests to handle potential network or server errors gracefully.","message":"HTTP status codes indicating errors (e.g., 4xx, 5xx) will typically trigger the `err` parameter in callbacks or the `.catch()` block in Promises, consistent with standard error handling for network requests. However, the exact behavior (e.g., if the response body is still accessible in error cases) depends on the specific error and version.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"For CommonJS, use `const tinyreq = require('tinyreq');`. For ESM, use `import tinyreq from 'tinyreq';`.","cause":"Attempting to use `tinyreq` after an incorrect import, likely a named import in ESM or incorrect destructuring in CJS.","error":"TypeError: tinyreq is not a function"},{"fix":"Verify the URL for typos and ensure network connectivity or correct DNS configuration. Try pinging the domain from your environment.","cause":"The hostname specified in the URL could not be resolved, indicating a DNS issue or incorrect URL.","error":"Error: getaddrinfo ENOTFOUND example.com"},{"fix":"Ensure you are using `tinyreq` version 3.2.5 or newer. Also, verify that `tinyreq` is called with a string URL or an object with a `url` property, which should return a Promise when no callback is provided.","cause":"This usually indicates an older version of `tinyreq` (pre-3.2.5) that did not fully support Promises for response body retrieval, or the function was called without a valid URL/options object preventing a Promise from being returned.","error":"TypeError: tinyreq(...).then is not a function"}],"ecosystem":"npm","meta_description":null}