{"id":16243,"library":"tiny-json-http","title":"Tiny JSON HTTP Client","description":"tiny-json-http is a minimalist HTTP client designed for making GET, POST, PUT, PATCH, and DELETE requests, primarily handling JSON payloads. Currently stable at version 7.5.1, it emphasizes a small footprint with zero external dependencies, making it particularly well-suited for constrained environments like AWS Lambda functions. The library offers a dual API, supporting both Node.js-style errback callbacks and Promises, which enables modern `async/await` usage. Its core differentiators include automatically assuming buffered JSON responses, a system-symmetric API, and a focus on simplicity over extensive configuration, making it a straightforward choice for basic HTTP interactions without the overhead of more feature-rich clients. The project maintains a steady release cadence for bug fixes and minor improvements, with major versions introducing breaking changes as needed.","status":"active","version":"7.5.1","language":"javascript","source_language":"en","source_url":"https://github.com/brianleroux/tiny-json-http","tags":["javascript"],"install":[{"cmd":"npm install tiny-json-http","lang":"bash","label":"npm"},{"cmd":"yarn add tiny-json-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add tiny-json-http","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"tiny-json-http is primarily a CommonJS module. Direct ESM `import` statements may require bundler configuration or specific `import` paths (e.g., `import tiny from 'tiny-json-http/index.js'`) for full compatibility, though bundlers often handle this seamlessly.","wrong":"import tiny from 'tiny-json-http'","symbol":"tiny","correct":"const tiny = require('tiny-json-http')"},{"note":"Individual methods like `get`, `post`, etc., are available directly on the module export object.","wrong":"import { get } from 'tiny-json-http'","symbol":"get","correct":"const { get } = require('tiny-json-http')"},{"note":"When using ESM `import`, ensure your environment or bundler correctly resolves CJS named exports for these methods.","wrong":"import { post } from 'tiny-json-http'","symbol":"post","correct":"const { post } = require('tiny-json-http')"}],"quickstart":{"code":"const tiny = require('tiny-json-http');\nconst url = 'https://jsonplaceholder.typicode.com/posts/1';\n\n(async function _iife() {\n  try {\n    const result = await tiny.get({ url });\n    console.log('Successfully fetched data:');\n    console.log('Headers:', result.headers);\n    console.log('Body:', result.body);\n  } catch (err) {\n    console.error('Error fetching data:', err.message);\n    if (err.statusCode) {\n      console.error('Status Code:', err.statusCode);\n      console.error('Error Body:', err.body); // Server error body if available\n    }\n  }\n})();","lang":"javascript","description":"Demonstrates making a GET request to an external API using async/await syntax and robust error handling."},"warnings":[{"fix":"For non-JSON responses, set `buffer: true` in the options to receive the raw response body as a Buffer, which you can then parse manually if needed. E.g., `tiny.get({ url, buffer: true })`.","message":"tiny-json-http automatically attempts to parse responses as JSON. If the server returns a non-JSON body (e.g., HTML error pages, plain text, or empty responses), this will result in a JSON parsing error.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"For APIs expecting DELETE parameters in the URL, manually construct the URL with query string parameters: `tiny.del({ url: 'https://example.com/item?id=123' })`. Avoid sending sensitive data in query strings.","message":"The `del` (DELETE) method accepts a `data` object, which is sent as the request body. Some REST APIs expect DELETE parameters in the URL query string rather than the request body, which can lead to unexpected behavior or API rejection.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Always include a `catch` block with Promises (e.g., `.catch(err => console.error(err))`) or wrap `await` calls in a `try...catch` block. When using callbacks, always check the `err` argument: `function(err, data) { if (err) { /* handle error */ } }`.","message":"While tiny-json-http supports both callbacks and Promises, failing to handle errors in either pattern can lead to unhandled promise rejections or uncaught exceptions, potentially crashing your application.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Implement external timeout mechanisms (e.g., `Promise.race` with a `setTimeout` promise) or wrap tiny-json-http calls in a mechanism that handles long-running requests, especially in critical path operations.","message":"The library does not expose options for configuring request timeouts directly in the public API excerpt provided. This means requests could hang indefinitely in cases of unresponsive servers, affecting application stability.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"For CommonJS, use `const tiny = require('tiny-json-http')`. If you must use `import`, ensure your bundler or Node.js environment is configured to handle CommonJS module imports correctly.","cause":"Attempting to use `import` syntax (e.g., `import tiny from 'tiny-json-http'`) in a pure CommonJS environment, or incorrect destructuring of the required module.","error":"TypeError: tiny.get is not a function"},{"fix":"If the response is not expected to be JSON, set the `buffer: true` option to receive the raw response body. You can then check its content type or parse it manually if desired.","cause":"The server responded with an HTML page (e.g., an error page), plain text, or an empty body, but tiny-json-http automatically attempted to parse it as JSON.","error":"SyntaxError: Unexpected token < in JSON at position 0 (or similar JSON parsing error)"},{"fix":"Verify the URL for typos, check your network connectivity, and ensure the target server is online and accessible from where your application is running. Implement retry logic for transient network issues.","cause":"The specified `url` is incorrect, the domain could not be resolved (DNS error), or the target server is unreachable or refused the connection.","error":"getaddrinfo ENOTFOUND example.com (or similar network error like ECONNREFUSED)"},{"fix":"Always add a `.catch()` method to promise chains (e.g., `tiny.get(...).then(...).catch(err => ...)`) or wrap `await` calls in a `try...catch` block to gracefully handle errors.","cause":"A promise returned by tiny-json-http was rejected due to an error (e.g., network failure, server error response), but there was no `.catch()` handler or `try...catch` block to handle the error.","error":"UnhandledPromiseRejectionWarning: [error message]"}],"ecosystem":"npm"}