{"library":"request-etag","title":"ETag-based HTTP Response Caching","description":"request-etag is a small, in-memory module designed for ETag-based HTTP response caching. It manages the `If-None-Match` header automatically for subsequent GET requests to the same URL, retrieving cached bodies for 304 Not Modified responses. The package currently leverages `lru-cache` for its underlying caching mechanism, which can be configured with options like `max` size. Crucially, `request-etag` defaults to using the `request` library as its HTTP client, which has been officially deprecated and is no longer maintained since February 11th, 2020. While an alternative HTTP client can be injected, it *must* adhere to the `request` library's API signature. The package's current stable version is 2.0.3, but its reliance on a deprecated core dependency suggests a slow or inactive release cadence, limiting its suitability for new projects. Its primary differentiator is its focused, lightweight approach to abstracting ETag caching logic.","language":"javascript","status":"deprecated","last_verified":"Wed Apr 22","install":{"commands":["npm install request-etag"],"cli":null},"imports":["const ETagRequest = require('request-etag');","const eTagRequest = new ETagRequest(cacheConfig, modernHttpClient);","eTagRequest(url, function (error, response, body) { /* ... */ });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const ETagRequest = require('request-etag');\nconst request = require('request'); // In a real application, use a modern HTTP client compatible with 'request' API\n\n// Configure the cache, e.g., max 10MB to store response bodies\nconst cacheConfig = {\n    max: 10 * 1024 * 1024 // 10MB limit for the cache\n};\n\n// Initialize ETagRequest. In a production environment, 'request' should be replaced \n// with a modern, maintained HTTP client that provides the same API signature.\nconst eTagRequest = new ETagRequest(cacheConfig, request);\n\n// Define a target URL for caching\nconst urlToCache = 'https://www.google.com/'; \n\nconsole.log('--- First request (expecting 200 OK) ---');\neTagRequest(urlToCache, function (error, response, body) {\n    if (error) {\n        console.error('Initial request failed:', error);\n        return;\n    }\n\n    if (response.statusCode === 200) {\n        console.log(`Status: ${response.statusCode} - Body retrieved from actual HTTP response.`);\n        // console.log(body.substring(0, 100) + '...'); // Log a snippet of the body\n    } else {\n        console.log(`Initial request unexpected status: ${response.statusCode}`);\n    }\n\n    console.log('\\n--- Second request (expecting 304 Not Modified from cache) ---');\n    eTagRequest(urlToCache, function (error2, response2, body2) {\n        if (error2) {\n            console.error('Second request failed:', error2);\n            return;\n        }\n\n        if (response2.statusCode === 304) {\n            console.log(`Status: ${response2.statusCode} - Body retrieved from internal cache.`);\n            // console.log(body2.substring(0, 100) + '...'); // Log a snippet of the cached body\n        } else if (response2.statusCode === 200) {\n            console.log(`Status: ${response2.statusCode} - Unexpected 200 on second request, cache might be bypassed.`);\n        } else {\n            console.log(`Second request unexpected status: ${response2.statusCode}`);\n        }\n    });\n});","lang":"javascript","description":"This quickstart demonstrates how to initialize `request-etag` with a cache configuration and perform ETag-aware GET requests, showing the behavior of both initial 200 OK and subsequent 304 Not Modified responses with cached bodies.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}