smart-http
raw JSON → 1.2.0 verified Sat Apr 25 auth: no javascript
A minimal HTTP client library for Node.js with a focus on simplicity and ease of use. Version 1.2.0 is the current stable release. The package provides basic HTTP request functionality with automatic JSON parsing, support for custom headers, and stream handling. It differentiates itself by requiring no external dependencies and offering a straightforward API for common use cases, though it lacks advanced features like interceptors or cancellation found in larger libraries. Released on an ad-hoc cadence with no recent updates.
Common errors
error TypeError: http.get is not a function ↓
cause Attempting to use require() in an ESM environment or wrong import style.
fix
Use import http from 'smart-http' instead of const http = require('smart-http').
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported ↓
cause Trying to require() an ESM-only package from CommonJS.
fix
Convert the importing module to ESM (use 'import' statements) or use dynamic import().
error Property 'data' does not exist on type 'SmartHttpResponse' ↓
cause TypeScript does not have type definitions for the response.
fix
Declare a module augmentation for 'smart-http' or cast response as any.
Warnings
gotcha Package has no exported types; TypeScript users must define their own interfaces for request/response. ↓
fix Declare module augmentation or use @types/smart-http if available.
gotcha The .get/.post methods do not support request cancellation or timeout by default; configure via AbortController manually. ↓
fix Pass a signal option from AbortController.timeout() to enable cancellation.
deprecated The 'data' event listener pattern is deprecated; use async/await or promise chaining instead. ↓
fix Switch to promise-based API for new code.
gotcha Response body is not automatically JSON-parsed for status codes outside 2xx; manual parsing required. ↓
fix Check response.ok and then JSON.parse(response.data) for non-2xx responses.
gotcha Multipart form data is not supported natively; use FormData polyfill or another library. ↓
fix Use 'form-data' package and pipe it to a request.
Install
npm install smart-http yarn add smart-http pnpm add smart-http Imports
- default wrong
const http = require('smart-http')correctimport http from 'smart-http' - request
import { request } from 'smart-http' - SmartHttp wrong
import { SmartHttp } from 'smart-http'correctimport SmartHttp from 'smart-http'
Quickstart
import http from 'smart-http';
async function fetchData() {
try {
const response = await http.get('https://api.example.com/data', {
headers: { 'Authorization': `Bearer ${process.env.API_KEY ?? ''}` }
});
console.log(response.data);
} catch (error) {
console.error('Request failed:', error);
}
}
fetchData();