@shivanshusahu/http-helper
v2.0.2
Published
Lightweight Node.js HTTP helper for GET and POST requests
Maintainers
Readme
@shivanshusahu/http-helper
A lightweight and customizable HTTP helper utility for Node.js built with TypeScript.
Supports timeouts, automatic retries, custom headers, and HTTP methods — perfect for building scalable and resilient APIs.
🚀 Features
- ✅ Timeout support
- 🔁 Retry logic (configurable)
- 🧰 Custom headers & HTTP methods
- 📦 ESM support
- ⚙️ Written in TypeScript
- 🧪 Easy to test and extend
📦 Installation
npm install @shivanshusahu/http-helper
Usage
import { request } from "@shivanshusahu/http-helper";
const run = async () => {
try {
const response = await request(
"https://jsonplaceholder.typicode.com/posts/1",
{
method: "GET",
headers: {
Accept: "application/json",
},
timeout: 3000,
retries: 2,
}
);
console.log("Response Body:", response);
} catch (err) {
console.error("Error:", err.message);
}
};
run();Options
interface RequestOptions {
method?: string; // GET, POST, PUT, DELETE etc.
headers?: Record<string, string>; // Custom HTTP headers
timeout?: number; // Timeout in milliseconds
retries?: number; // Number of retry attempts
}