@bernierllc/http-client-base
v0.6.0
Published
Shared HTTP client utilities for API and download connectors
Readme
@bernierllc/http-client-base
Shared HTTP client utilities for API and download connectors, wrapping axios with retry and rate limiting support.
Overview
This core package provides a unified HTTP client interface built on top of axios, with integrated retry policies and rate limiting. It's designed to be used by both API connectors and download connectors to ensure consistent HTTP behavior across the data ingestion system.
Installation
npm install @bernierllc/http-client-baseUsage
Basic Usage
import { HttpClient } from '@bernierllc/http-client-base';
const client = new HttpClient({
baseURL: 'https://api.example.com',
timeout: 30000
});
// GET request
const response = await client.get('/users');
console.log(response.data);
// POST request
const result = await client.post('/users', { name: 'John' });With Authentication
const client = new HttpClient({
baseURL: 'https://api.example.com',
auth: {
type: 'bearer',
token: 'your-token-here'
}
});With Retry and Rate Limiting
const client = new HttpClient({
baseURL: 'https://api.example.com',
retryConfig: {
enabled: true,
maxAttempts: 3,
retryableStatusCodes: [429, 500, 502, 503, 504]
},
rateLimitConfig: {
enabled: true,
requestsPerSecond: 10,
requestsPerMinute: 100
}
});With Interceptors
const client = new HttpClient({
baseURL: 'https://api.example.com',
interceptors: {
request: [
{
onFulfilled: (config) => {
config.headers['X-Custom-Header'] = 'value';
return config;
}
}
],
response: [
{
onFulfilled: (response) => {
// Transform response
return response;
}
}
]
}
});File Download
const buffer = await client.download(
'https://example.com/file.pdf',
(progress) => {
console.log(`Downloaded: ${progress.percent}%`);
}
);API Reference
HttpClient
Main HTTP client class wrapping axios.
Constructor
new HttpClient(config?: HttpClientConfig)Methods
request<T>(options: HttpRequestOptions): Promise<HttpResponse<T>>- Make HTTP requestget<T>(url: string, options?): Promise<HttpResponse<T>>- GET requestpost<T>(url: string, data?, options?): Promise<HttpResponse<T>>- POST requestput<T>(url: string, data?, options?): Promise<HttpResponse<T>>- PUT requestpatch<T>(url: string, data?, options?): Promise<HttpResponse<T>>- PATCH requestdelete<T>(url: string, options?): Promise<HttpResponse<T>>- DELETE requestdownload(url: string, onProgress?, options?): Promise<Buffer>- Download file
Dependencies
axios@^1.7.0- HTTP client library@bernierllc/retry-policy- Retry logic@bernierllc/rate-limiter- Rate limiting
License
Bernier LLC - Limited Use License
