Request Promise Core

1.1.4 · abandoned · verified Wed Apr 22

request-promise-core is a foundational library that provides Promise support for the now-deprecated 'request' HTTP client. It is not intended for direct use by most applications; instead, it serves as the core logic for higher-level packages like `request-promise`, `request-promise-any`, `request-promise-bluebird`, and `request-promise-native`. Published last on July 22, 2020, this package's development has ceased, mirroring the abandonment of its peer dependency, 'request'. It offers a mechanism to inject Promise capabilities (e.g., `.then()`, `.catch()`) into the `request` object via a `configure` function, requiring a compatible Promise implementation to be explicitly passed. Due to the deprecation of its upstream 'request' dependency, this package is considered obsolete and should not be used in new projects.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to apply Promise capabilities to the 'request' library using `request-promise-core`, including safe loading with `stealthy-require` and basic error handling.

const stealthyRequire = require('stealthy-require');
const request = stealthyRequire(require.cache, function () {
    return require('request');
});

const configure = require('request-promise-core/configure/request2');

configure({
    request: request,
    PromiseImpl: Promise,
    expose: [
        'then',
        'catch',
        'promise'
    ],
    constructorMixin: function (resolve, reject) {
        // `this` is the request object
    }
});

// 3. Use request with its promise capabilities

request('https://api.example.com/data')
    .then(function (body) {
        console.log('Received data:', body.substring(0, 100) + '...');
    })
    .catch(function (err) {
        console.error('Request failed:', err.message);
    });

// Example with environment variable for a real API call (mocked here)
const API_KEY = process.env.EXAMPLE_API_KEY ?? 'MOCK_API_KEY';
request(`https://api.example.com/secure-data?key=${API_KEY}`)
    .then(function (body) {
        console.log('Secure data access successful (mocked):', body.substring(0, 100) + '...');
    })
    .catch(function (err) {
        console.error('Secure data access failed (mocked):', err.message);
    });

view raw JSON →