Lightweight Node.js HTTP Client

2.0.3 · active · verified Tue Apr 21

btch-http is a lightweight and type-safe HTTP client for Node.js, built directly on the Node.js `https` module, ensuring zero external dependencies. The current stable version is 2.0.3, with recent minor updates following a major version 2.0.0 release. It differentiates itself by offering full TypeScript support out-of-the-box, smart error handling that consolidates network, timeout, and HTTP status code (>=300) errors into a custom `HttpError` class, and comprehensive timeout support. It provides both a quick one-liner `HttpGet` function for simple GET requests with URL encoding and a full-featured `HttpClient` class for more complex interactions involving configurable base URLs, versions, default headers, and POST requests with JSON bodies or custom headers. It requires Node.js >=20.18.1.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a quick, one-liner GET request using `HttpGet` to retrieve data from a TikTok video downloader API.

import { HttpGet } from 'btch-http';

const tiktokVideoUrl = 'https://www.tiktok.com/@omagadsus/video/7025456384175017243';

async function downloadTikTokData() {
  try {
    // The `HttpGet` function automatically appends `?url=...` for the second argument.
    const data = await HttpGet(
      'ttdl',
      tiktokVideoUrl,
      '1.0.0', // Client version
      30000,   // Timeout in milliseconds
      'https://backend1.tioo.eu.org' // Base URL for the endpoint
    );
    console.log('Download URL:', data.video);
    console.log('Raw data:', data);
  } catch (error) {
    if (error instanceof Error) {
      console.error('Failed to download TikTok data:', error.message);
    } else {
      console.error('An unknown error occurred:', error);
    }
  }
}

downloadTikTokData();

view raw JSON →