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-5/

API Request Manager with Timeout Control

Build a simple API request manager that makes HTTP requests with configurable timeout handling. The manager should automatically cancel requests that take too long to complete.

Requirements

Your solution should:

  1. Initialize a configured HTTP client that makes requests with a maximum timeout duration
  2. Handle timeout scenarios by automatically canceling requests that exceed the timeout threshold
  3. Support multiple concurrent requests each with their own timeout tracking
  4. Provide clear feedback when a request times out versus when it completes successfully

Functional Specifications

Request Manager

Create a request manager that:

  • Accepts a base timeout value during initialization (in milliseconds)
  • Makes HTTP GET requests to specified URLs
  • Returns a promise that resolves with the response or rejects on timeout
  • Automatically cancels the underlying request when a timeout occurs

Timeout Behavior

When a request times out:

  • The request should be canceled/aborted
  • A clear timeout error should be raised
  • No further processing of the response should occur

Success Behavior

When a request completes within the timeout:

  • The response should be returned successfully
  • The response should include status code and response data

Test Cases

  • When a request completes within 2000ms timeout, it should return the response successfully @test
  • When a request takes longer than 500ms timeout, it should reject with a timeout error @test
  • When making multiple concurrent requests with different timeouts, each should be handled independently @test

Implementation

@generates

API

/**
 * Creates a request manager with timeout support
 *
 * @param {number} timeoutMs - Default timeout in milliseconds
 * @returns {Object} Request manager with makeRequest method
 */
function createRequestManager(timeoutMs) {
  // IMPLEMENTATION HERE
}

/**
 * Makes an HTTP GET request with timeout handling
 *
 * @param {string} url - The URL to request
 * @returns {Promise} Promise that resolves with response or rejects on timeout
 */
// makeRequest method should be available on the returned object

module.exports = {
  createRequestManager
};

Dependencies { .dependencies }

rest { .dependency }

Provides RESTful HTTP client functionality with interceptor support and timeout handling.

Version

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