CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rest

RESTful HTTP client library with composable interceptor architecture for Node.js and browsers

76

1.28x
Overview
Eval results
Files

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.

Install with Tessl CLI

npx tessl i tessl/npm-rest

tile.json