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.
npm install tiny-json-httpVerified import paths — ran on the pinned version, not inferred.
Demonstrates making a GET request to an external API using async/await syntax and robust error handling.
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 })`.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.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 */ } }`.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.
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.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.
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.
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.
No dependency data recorded yet.