2.0.2 โข Published 3 months ago
@shivanshusahu/http-helper v2.0.2
@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
}