Supra-http is a fast HTTP client for Node.js that integrates a circuit breaker pattern to enhance resilience in distributed systems. It is built on top of the 'opossum' library for robust circuit breaking capabilities, allowing it to gracefully handle failures in remote services and prevent cascading outages. The package is currently at version 1.8.5. While the project description mentions forthcoming documentation, the last update on GitHub was in March 2023, and the last npm publish was also over a year ago, suggesting a maintenance or possibly abandoned status rather than active development. Its key differentiators include built-in circuit breaking and reported performance advantages over alternatives like `request` and `requestretry` according to its benchmarks. It supports gzip and brotli decompression for Node.js versions 10.17.x and above.
npm install supra-httpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate `supra-http` and make a GET request to a public API with explicit circuit breaker configuration, including error handling for when the circuit trips or the request fails.
Ensure your Node.js environment is at least version 10.17.0 for full decompression support, or consider upgrading to a more recent LTS version of Node.js for better compatibility and security.
For new projects, consider more actively maintained HTTP clients with circuit breaking capabilities or standalone circuit breaker libraries. For existing projects, be aware that you might need to fork or contribute fixes yourself for future compatibility or security issues.
Review the `opossum` changelog for any major version updates beyond what `supra-http` was initially built against. If upgrading `supra-http` or its dependencies, thoroughly test circuit breaker behavior, especially configuration options like `errorThresholdPercentage`, `resetTimeout`, and `fallback` functions.
This is expected behavior. Implement a `catch` block for `client.request` to handle this error. Provide a graceful fallback mechanism (e.g., returning cached data, a default value, or queuing the request) instead of failing the entire operation. Configure `resetTimeout` to allow the circuit to automatically transition to `HALF_OPEN` state to re-test the service.
Ensure you are instantiating the client: `import SupraClient from 'supra-http'; const client = new SupraClient(); client.request(...)`.
Always chain a `.catch()` method or use `try...catch` with `await` to handle potential network errors and timeouts from `client.request` promises. Adjust the `timeout` option in `client.request` if the default is too aggressive for your target service.