A lightweight, type-safe HTTP client built on Node.js https module.
Includes a quick HttpGet function and a full-featured HttpClient class with GET/POST, timeout, headers, and error handling.
- Zero dependencies – uses only Node.js
https - TypeScript-first – full type safety
- HttpGet – one-liner GET with URL encoding
- HttpClient – reusable client with config, headers, query params, POST
- Smart error handling –
HttpErrorwith status & response - Timeout support – automatic cleanup on timeout
Using npm:
npm install btch-httpUsing yarn:
yarn add btch-httpUsing pnpm:
pnpm add btch-httpUsing bun:
bun add btch-httpimport { HttpGet } from 'btch-http';
const result = await HttpGet<any>(
'ttdl', // endpoint
'https://tiktok.com/@user/video/123', // url to scrape
'1.0.0', // client version
30000, // timeout (ms)
'https://backend1.tioo.eu.org' // base URL
);
console.log(result);Automatically appends
?url=...and sets proper headers.
import { HttpClient } from 'btch-http';
const client = new HttpClient({
baseUrl: 'https://api.example.com',
version: '2.0.0',
timeout: 10000,
});
// GET with query params
const res1 = await client.get<{ id: number }>('users', { active: '1' });
console.log(res1.data);
// POST with JSON body
const res2 = await client.post<{ success: boolean }>('login', {
username: 'john',
password: 'secret'
});
console.log(res2.status, res2.data);
// POST with custom headers
const res3 = await client.post('upload', { file: '...' }, {
Authorization: 'Bearer xyz'
});interface HttpClientConfig {
baseUrl: string;
version: string;
timeout?: number; // default: 60000
defaultHeaders?: Record<string, string>;
}interface HttpResponse<T> {
status: number;
statusText: string;
data: T | null;
headers: Record<string, string>;
}try {
await client.get('not-found');
} catch (error) {
if (error instanceof HttpError) {
console.log(error.status); // e.g. 404
console.log(error.message); // e.g. "Not Found"
console.log(error.response?.data);
}
}
HttpErroris thrown for:
- HTTP status ≥ 300
- Network errors
- Timeouts
- JSON parse failures
export { HttpGet, HttpClient, HttpError };
export type { HttpClientConfig, HttpResponse };import { HttpGet } from 'btch-http';
const url = 'https://www.tiktok.com/@omagadsus/video/7025456384175017243';
const data = await HttpGet(
'ttdl',
url,
'1.0.0',
30000,
'https://backend1.tioo.eu.org'
);
console.log('Download URL:', data.video);MIT