tessl install tessl/npm-rest@2.0.0RESTful HTTP client library with composable interceptor architecture for Node.js and browsers
Agent Success
Agent success rate when using this tile
76%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.29x
Baseline
Agent success rate without this tile
59%
Build a simple HTTP request monitoring utility that can track ongoing requests and cancel them when needed. The utility should support initiating multiple concurrent HTTP requests and provide the ability to cancel individual or all pending requests before they complete.
Your implementation should include:
initiateRequest(url, options) that starts an HTTP request and returns a request handle that can be used to cancel it latercancelRequest(handle) that cancels a specific ongoing request using its handlecancelAllRequests() that cancels all currently pending requestsgetActiveRequestCount() that returns the number of currently active (non-completed, non-canceled) requestsThe utility should properly track request lifecycle states (active, completed, canceled) and ensure that canceled requests are properly cleaned up.
cancelAllRequests() should cancel all pending requests @testgetActiveRequestCount() should correctly reflect the number of active requests @test@generates
/**
* Initiates an HTTP request and returns a handle for managing it.
*
* @param {string} url - The URL to request
* @param {object} [options] - Optional request configuration
* @returns {object} Handle object with cancel method and request promise
*/
function initiateRequest(url, options) {
// IMPLEMENTATION HERE
}
/**
* Cancels a specific request using its handle.
*
* @param {object} handle - The request handle returned by initiateRequest
*/
function cancelRequest(handle) {
// IMPLEMENTATION HERE
}
/**
* Cancels all currently pending requests.
*/
function cancelAllRequests() {
// IMPLEMENTATION HERE
}
/**
* Returns the number of currently active requests.
*
* @returns {number} Count of active requests
*/
function getActiveRequestCount() {
// IMPLEMENTATION HERE
}
module.exports = {
initiateRequest,
cancelRequest,
cancelAllRequests,
getActiveRequestCount
};Provides HTTP client functionality with request cancellation support.
@satisfied-by