tessl install tessl/npm-rest@2.0.0RESTful 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%
Build a request manager that efficiently handles conditional API requests using deferred execution. The system should only execute HTTP requests when their results are actually needed, avoiding unnecessary network calls.
Your implementation should provide a function createConditionalRequest that wraps an HTTP request configuration and returns a deferred promise. The HTTP request should not execute immediately upon creation, but only when the promise is consumed (via .then(), .catch(), etc.).
The function should:
.then() or similar methodsRequest configuration properties:
path: The API endpoint URL (required)method: HTTP method like GET, POST, etc. (optional, defaults to GET)headers: HTTP headers object (optional)entity: Request body for POST/PUT requests (optional)// Create a conditional request that won't execute immediately
const userRequest = createConditionalRequest({
path: '/api/users/123',
method: 'GET'
});
// Request executes only when result is needed
userRequest.then(response => {
console.log('User data:', response.entity);
});
// Chain multiple conditional requests
const orderRequest = createConditionalRequest({
path: '/api/orders',
method: 'GET'
});
// Both requests only execute when final result is accessed
userRequest
.then(user => orderRequest)
.then(orders => {
console.log('Orders:', orders.entity);
});.then() is called @test@generates
/**
* Creates a conditional request that defers execution until accessed
* @param {object} config - Request configuration
* @param {string} config.path - API endpoint path
* @param {string} [config.method='GET'] - HTTP method
* @param {object} [config.headers] - HTTP headers
* @param {any} [config.entity] - Request body for POST/PUT
* @returns {Promise} A promise-like object that defers HTTP request execution
*/
function createConditionalRequest(config);
module.exports = { createConditionalRequest };Provides RESTful HTTP client functionality with lazy promise evaluation support.
@satisfied-by