Requestify - Node HTTP Client with Caching

0.2.5 · abandoned · verified Wed Apr 22

Requestify is an HTTP client for Node.js, designed to simplify making HTTP requests and provide built-in caching capabilities. It utilizes the Q promise library for asynchronous operations, returning promises for all network calls. As of its last major release, version 0.2.5 (published in 2016), it supports in-memory, Redis, and MongoDB caching via pluggable transporters. The package was primarily built for Node.js environments around `~0.10.x`, making it incompatible with modern Node.js runtimes. Its key differentiators at the time were its promise-based API (using Q) and an extensible caching mechanism. The project appears to be abandoned, with no significant updates or maintenance for nearly a decade.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic GET and POST requests, shows how to set encoding, and illustrates the use of Requestify's built-in caching mechanism with the default in-memory transporter. It highlights the promise-based nature of the API using the `then` method.

const requestify = require('requestify');

async function performRequests() {
  // Set a custom encoding (optional, utf8 is default)
  requestify.setEncoding('utf8');

  // Example GET request
  console.log('Performing GET request...');
  try {
    const getResponse = await requestify.get('https://httpbin.org/get').then(function(response) {
      return response.getBody(); // Q-promise .then()
    });
    console.log('GET Response Body:', getResponse);
  } catch (error) {
    console.error('GET Error:', error.message || error.code || error);
  }

  // Example POST request with JSON body
  console.log('\nPerforming POST request...');
  try {
    const postResponse = await requestify.post('https://httpbin.org/post', {
      hello: 'world',
      timestamp: new Date().toISOString()
    }).then(function(response) {
      return response.getBody(); // Q-promise .then()
    });
    console.log('POST Response Body:', postResponse);
  } catch (error) {
    console.error('POST Error:', error.message || error.code || error);
  }

  // Example GET request with caching enabled (requires cache transporter setup)
  console.log('\nPerforming cached GET request...');
  // Using the default in-memory cache transporter
  const coreCacheTransporters = requestify.coreCacheTransporters;
  requestify.cacheTransporter(coreCacheTransporters.inMemory());
  try {
    const cachedGetResponse = await requestify.get('https://httpbin.org/delay/1', { 
      cache: { cache: true, expires: 5000 } // Cache for 5 seconds
    }).then(function(response) {
      return response.getBody();
    });
    console.log('Cached GET Response Body (first call):', cachedGetResponse);

    // Immediately fetch again, should be from cache if within 5 seconds
    const cachedGetResponse2 = await requestify.get('https://httpbin.org/delay/1', { 
      cache: { cache: true, expires: 5000 } 
    }).then(function(response) {
      return response.getBody();
    });
    console.log('Cached GET Response Body (second call, should be fast):', cachedGetResponse2);
  } catch (error) {
    console.error('Cached GET Error:', error.message || error.code || error);
  }
}

performRequests();

view raw JSON →