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

Request Deduplication Interceptor

Build a custom interceptor that prevents duplicate concurrent requests to the same URL by reusing in-flight requests.

Requirements

When multiple requests are made to the same URL while a previous request is still pending, the interceptor should:

  1. Identify duplicate requests based on the complete request path
  2. Return the same response promise for all duplicate requests instead of making multiple network calls
  3. Clear the cached promise once the request completes (success or error)
  4. Support request cancellation - if the original request is canceled, all duplicate requests should receive the same canceled response

Implementation Notes

The solution should:

  • Create a custom interceptor that wraps the HTTP client
  • Maintain a cache of in-flight requests keyed by URL
  • For duplicate requests, return the cached promise instead of making a new network call
  • Clean up completed requests from the cache after they resolve or reject

Test Cases

  • Making concurrent requests to the same URL returns identical response objects @test
  • Sequential requests to the same URL each trigger their own network call @test
  • Requests to different URLs are not deduplicated @test
  • When the original request fails, all duplicate requests receive the same error @test

@generates

API

/**
 * Creates a deduplication interceptor that prevents concurrent duplicate requests
 * @returns {Function} An interceptor function
 */
function dedupInterceptor() {
  // Implementation here
}

module.exports = dedupInterceptor;

Dependencies { .dependencies }

rest { .dependency }

Provides the HTTP client library with interceptor support.

Version

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