sl-request: Simplified HTTP Client (Fork of Deprecated 'request')
sl-request is a Node.js HTTP client, version 1.0.8, explicitly stated as a fork of the widely used but now deprecated `request` library, primarily for internal use by sealights.io. This package attempts to provide a simplified API for making HTTP calls, supporting HTTPS, automatic redirects, streaming, and various request body types (forms, multipart). However, inheriting its core from the original `request` library, it carries the same limitations and risks, including a callback-centric API, known security vulnerabilities, and a lack of modern maintenance. The original `request` library was officially deprecated in February 2020 due to its unmaintained status, security risks, and outdated architectural patterns that do not align with modern JavaScript and Node.js paradigms. Users should be aware that `sl-request` likely shares these fundamental issues and does not offer a current, actively maintained solution for HTTP requests. Release cadence is infrequent, reflecting its internal-use nature and the deprecated status of its upstream.
Common errors
-
Error: Cannot find module 'request'
cause Attempting to `require('request')` or `import 'request'` instead of `sl-request` when the package installed is `sl-request`.fixEnsure you are importing the correct package name: `const request = require('sl-request');` or `import request from 'sl-request';`. -
DeprecationWarning: request has been deprecated, see https://github.com/request/request/issues/3142
cause This warning directly indicates that the underlying `request` library, which `sl-request` is forked from, is deprecated. This warning will appear even for `sl-request` installations due to its origin.fixAcknowledge that `sl-request` inherits the deprecation status of its upstream. While the warning is expected, the recommended fix is to migrate to a modern, actively maintained HTTP client. -
TypeError: request is not a function
cause This usually happens when `request` is imported incorrectly, such as `import { request } from 'sl-request';` instead of a default import, or if the `require` statement doesn't correctly assign the function.fixUse the correct import pattern: for ESM `import request from 'sl-request';` or for CJS `const request = require('sl-request');`. The main export is a callable function, not an object with named properties that need destructuring.
Warnings
- breaking The `sl-request` package is a direct fork of the original `request` library, which has been officially deprecated since February 2020 and is no longer maintained. This means `sl-request` inherently carries all the maintenance, security, and architectural issues of the unmaintained `request` library.
- breaking Due to its unmaintained nature, `sl-request` (and `request`) is susceptible to unpatched security vulnerabilities. Continuing to use it can expose your application to critical security risks, including supply chain attacks, data breaches, or denial-of-service vulnerabilities.
- gotcha The API is primarily callback-based, which can lead to 'callback hell' in complex asynchronous flows. While some promise-based wrappers existed for the original `request`, `sl-request` does not natively provide modern `async/await` support without manual promisification.
- gotcha The original `request` library (and thus its forks) was known for potential memory leaks and performance inefficiencies, especially with high concurrency or large data streams, due to its older codebase and lack of modern optimizations.
Install
-
npm install sl-request -
yarn add sl-request -
pnpm add sl-request
Imports
- request
const request = require('request');import request from 'sl-request';
- request (CommonJS)
import request from 'sl-request';
const request = require('sl-request'); - request.get, request.post
import { get } from 'sl-request';import request from 'sl-request'; request.get('...');
Quickstart
import request from 'sl-request';
import fs from 'fs';
// Basic GET request
request('http://www.google.com', function (error, response, body) {
if (error) {
console.error('Error:', error);
return;
}
console.log('statusCode:', response && response.statusCode);
console.log('Body snippet:', body.substring(0, 100) + '...');
});
// Stream a file to a PUT request
// For demonstration, create a dummy file first
fs.writeFileSync('temp_upload.json', JSON.stringify({ message: 'Hello from sl-request' }));
fs.createReadStream('temp_upload.json')
.pipe(request.put('http://httpbin.org/put', function (error, response, body) {
if (error) {
console.error('PUT Error:', error);
return;
}
console.log('PUT statusCode:', response && response.statusCode);
console.log('PUT Response:', body);
fs.unlinkSync('temp_upload.json'); // Clean up dummy file
}));
// Example of error handling for streaming
request.get('http://nonexistent-domain.invalid/image.png')
.on('error', function(err) {
console.error('Streaming error caught:', err.message);
})
.pipe(fs.createWriteStream('downloaded_image.png'));