Supra HTTP Client with Circuit Breaking
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.
Common errors
-
Error: CircuitBreaker is open
cause The configured failure threshold was met or exceeded, causing the circuit breaker to 'trip' and enter the OPEN state, preventing further requests to the protected service.fixThis 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. -
TypeError: client.request is not a function
cause The `supra-http` client needs to be instantiated before its methods, like `request`, can be called. This error often occurs when attempting to call `supra-http.request()` directly after import without `new SupraClient()`.fixEnsure you are instantiating the client: `import SupraClient from 'supra-http'; const client = new SupraClient(); client.request(...)`. -
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: X): Error: connect ETIMEDOUT
cause The underlying HTTP request timed out or failed to connect, and the promise was not handled with a `.catch()` block. This is a common network error or an issue with the target API.fixAlways 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.
Warnings
- gotcha The README states that for gzip and brotli decompression, Node.js version 10.17.x or higher is required, even though the `engines` field in `package.json` specifies `>=10.16`. This minor version difference can lead to unexpected decompression failures if running on exactly Node.js 10.16.x.
- deprecated The package appears to be in maintenance mode, with the last commit on GitHub in March 2023 and the last npm publish around the same time. The README mentions 'Documentation will be released soon,' which is outdated. This indicates limited or no active development, meaning it may not receive updates for newer Node.js versions, security patches, or feature enhancements.
- breaking As `supra-http` relies on `opossum` for its circuit breaking logic, major updates to `opossum` could introduce breaking changes to how circuit breaker options are configured or how events are emitted, potentially affecting `supra-http`'s behavior. The `opossum` library has had releases up to version 9.0.0 (May 2025) since `supra-http`'s last update.
Install
-
npm install supra-http -
yarn add supra-http -
pnpm add supra-http
Imports
- SupraClient
const SupraClient = require('supra-http');import SupraClient from 'supra-http'; const client = new SupraClient();
- request
import SupraClient from 'supra-http'; const client = new SupraClient(); client.request('apiCallName', 'https://my-api/endpoint', { method: 'get' }); - CircuitBreakerOptions
import type { CircuitBreakerOptions } from 'supra-http';
Quickstart
import SupraClient from 'supra-http';
const client = new SupraClient();
async function fetchData() {
try {
// Example GET request with basic circuit breaking options
const response = await client.request('myApiGetCall', 'https://jsonplaceholder.typicode.com/todos/1', {
method: 'get',
json: true,
timeout: 2000, // Request timeout
errorThresholdPercentage: 50, // 50% errors to trip the circuit
resetTimeout: 10000, // How long to wait before trying again (half-open state)
enabled: true // Enable circuit breaker for this call
});
console.log('API Response:', response.json);
} catch (error) {
console.error('API Call Failed or Circuit Tripped:', error.message);
// Implement fallback logic here if needed
}
}
fetchData();