RESTful HTTP client library with composable interceptor architecture for Node.js and browsers
76
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
Install with Tessl CLI
npx tessl i tessl/npm-restevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10