CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-rest

tessl install tessl/npm-rest@2.0.0

RESTful 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%

task.mdevals/scenario-6/

Request Monitor with Cancellation Support

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.

Requirements

Your implementation should include:

  1. A function initiateRequest(url, options) that starts an HTTP request and returns a request handle that can be used to cancel it later
  2. A function cancelRequest(handle) that cancels a specific ongoing request using its handle
  3. A function cancelAllRequests() that cancels all currently pending requests
  4. A function getActiveRequestCount() that returns the number of currently active (non-completed, non-canceled) requests

The utility should properly track request lifecycle states (active, completed, canceled) and ensure that canceled requests are properly cleaned up.

Test Cases

  • Starting a request and immediately canceling it should prevent the request from completing @test
  • Starting multiple requests and canceling one should only affect that specific request @test
  • Calling cancelAllRequests() should cancel all pending requests @test
  • getActiveRequestCount() should correctly reflect the number of active requests @test

Implementation

@generates

API

/**
 * 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
};

Dependencies { .dependencies }

rest { .dependency }

Provides HTTP client functionality with request cancellation support.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/rest@2.0.x
tile.json