Cogent is a simple HTTP request library built for Node.js and generators using co. It supports redirect resolution, timeout, automatic gunzip decompression, and first-class JSON parsing. The response can be buffered, saved to a file, or returned as parsed JSON. Options include retries, timeouts, and customizable request properties. Version 1.0.1 is stable but the package is part of the cojs ecosystem and has seen no recent updates. It relies on generators and the co library, making it less suitable for modern async/await workflows without additional wrapping.
npm install cogentVerified import paths — ran on the pinned version, not inferred.
Demonstrates fetching a JSON endpoint using a generator function, parsing JSON response, and logging the body.
Use async/await with a library that returns promises (e.g., node-fetch).
Wrap with co: const wrapped = co(require('cogent'));Check res.statusCode before accessing res.body.
Use yield* request(uri) inside a generator, or wrap with co.
Ensure the containing function is a generator (function*).