Tinyreq HTTP(s) Requests

3.4.3 · maintenance · verified Wed Apr 22

Tinyreq is a minimalist JavaScript library designed for making HTTP and HTTPS requests, aiming for simplicity and a small footprint. Currently at version 3.4.3, it offers both traditional callback-based and modern Promise-based APIs for handling responses. Its release cadence is generally conservative, with updates focusing on maintenance tasks such as documentation improvements, minor dependency upgrades (e.g., `follow-redirects`), and occasional bug fixes (e.g., addressing Promise handling in 3.2.5). A key differentiating factor is its commitment to being a "tiny" utility, providing core request functionality without the extensive feature sets found in larger HTTP clients, making it suitable for environments where bundle size and minimal dependencies are crucial.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates making basic GET requests using both callback and Promise patterns, and a POST request with data to an external endpoint.

const tinyreq = require("tinyreq");

// Make a basic GET request with a callback
tinyreq("http://example.com/", (err, body) => {
    if (err) {
        console.error("Callback GET error:", err);
        return;
    }
    console.log("Callback GET response body (first 100 chars):");
    console.log(body.substring(0, 100) + '...');
});

// Make a GET request with custom headers using Promises
tinyreq({
    url: "http://example.com/"
  , headers: {
        "User-Agent": "Tinyreq-App/1.0"
    }
}).then(body => {
    console.log("Promise GET response body (first 100 chars):");
    console.log(body.substring(0, 100) + '...');
}).catch(err => {
    console.error("Promise GET error:", err);
});

// Make a POST request with data to a test endpoint
tinyreq({
    url: "https://httpbin.org/post"
  , method: "POST"
  , data: {
        message: "Hello from tinyreq",
        timestamp: new Date().toISOString()
    }
}, (err, body) => {
    if (err) {
        console.error("Callback POST error:", err);
        return;
    }
    console.log("Callback POST response:", JSON.parse(body).json);
});

view raw JSON →