Lightweight, dependency-free HTTP/HTTPS transport client for Node.js.
Designed for extensibility, authentication strategies, and retry
handling.
- β
Native
http/https(no external dependencies) - π Built-in retry strategy (fixed or exponential backoff)
- π Pluggable authentication (Basic, Bearer, API Key, HMAC)
- π§© Extensible architecture (Factory & Strategy patterns)
- π¦ JSON-first request/response handling
- β‘ Lightweight and production-ready
npm install @minervajs/http-transportconst { HttpClient } = require('@minervajs/http-transport');
(async () => {
const client = new HttpClient({
timeout: 5000,
retries: 2
});
const response = await client.get('https://httpbin.org/get');
console.log(response.status);
console.log(response.data);
})();Creates a new HTTP client instance.
Option Type Default Description
timeout number 3000 Request timeout in milliseconds
retries number 0 Number of retry attempts
headers object {} Default headers
await client.get('https://api.example.com/users');await client.post('https://api.example.com/users', {
name: 'John'
});await client.request({
method: 'POST',
url: 'https://api.example.com/data',
body: { test: true },
headers: { 'X-Custom': 'Value' }
});Authentication is handled via the AuthFactory pattern.
const client = new HttpClient({
auth: {
type: 'basic',
username: 'admin',
password: 'secret'
}
});const client = new HttpClient({
auth: {
type: 'bearer',
token: 'your-jwt-token'
}
});const client = new HttpClient({
auth: {
type: 'apikey',
header: 'X-API-KEY',
value: 'your-api-key'
}
});Automatically signs the JSON payload.
const client = new HttpClient({
auth: {
type: 'hmac',
secret: 'your-secret',
algorithm: 'sha256'
}
});Adds the header:
X-Signature: <computed-hmac>
const client = new HttpClient({
retries: 2
});- Retries on thrown errors
- Supports exponential backoff
- Total attempts =
retries + 1
Example:
retries: 2 β 3 total attempts
{
status: number,
headers: object,
data: any
}If the response body is valid JSON β it is automatically parsed.
If not β it is returned as a raw string.
try {
await client.get('https://httpbin.org/status/404');
} catch (err) {
console.log(err.name); // HttpError
console.log(err.status); // 404
console.log(err.response); // Parsed response body
}const { HttpClient } = require('@minervajs/http-transport');
const client = new HttpClient({
timeout: 5000,
retries: 2,
headers: {
'X-App': 'MinervaJS'
},
auth: {
type: 'bearer',
token: 'my-token'
}
});
(async () => {
const res = await client.post(
'https://httpbin.org/post',
{ event: 'webhook-test' }
);
console.log(res.data);
})();BSD-2-Clause