npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

losi-tiny-http

v1.0.1

Published

Blazing-fast, zero-dependency HTTP client for Node & Browser

Readme

🚀 LosiTinyHttp

A lightweight, fetch-compatible HTTP client for browser and Node.js.
Supports interceptors, retries, timeouts, and cancellation — all with zero dependencies.


📦 Installation

npm install losi-tiny-http
# or
yarn add losi-tiny-http
# or
pnpm add losi-tiny-http

⚡ Quick Start

import { client } from "losi-tiny-http";

async function run() {
  const res = await client.get("https://jsonplaceholder.typicode.com/posts/1");
  console.log(res.data);
}

run();

✅ Works in both browser and Node.js — no extra setup required.


🧩 Create Your Own Instance

import { create } from "losi-tiny-http";

const api = create({
  baseURL: "https://jsonplaceholder.typicode.com",
  timeout: 5000,
  headers: {
    "Accept": "application/json",
  },
  retry: {
    attempts: 3,
    backoff: "exponential",
    delay: 500,
  },
});

const response = await api.get("/posts/1");
console.log(response.data);

🌐 HTTP Methods

await api.get("/posts/1");
await api.post("/posts", { title: "TinyHttp", body: "Lightweight HTTP" });
await api.put("/posts/1", { title: "Updated" });
await api.patch("/posts/1", { body: "Partial update" });
await api.delete("/posts/1");
await api.head("/posts/1");
await api.options("/posts");

🧱 Interceptors

Request Interceptor

api.interceptRequest(async (config) => {
  config.headers.Authorization = "Bearer my-token";
  console.log("➡️", config.method, config.url);
  return config;
});

Response Interceptor

api.interceptResponse(async (response) => {
  console.log("✅", response.status);
  return response;
});

Error Interceptor

api.interceptError(async (error) => {
  console.error("❌", error.message);
  return Promise.reject(error);
});

🔁 Retry Logic

const api = create({
  retry: {
    attempts: 3,
    backoff: "exponential", // or "fixed"
    delay: 300, // ms
  },
});

Automatically retries failed requests (network errors, timeouts, or 5xx).


⏱️ Timeout Support

const api = create({ timeout: 3000 });

try {
  await api.get("https://httpstat.us/200?sleep=5000");
} catch (err) {
  console.error("⏰ Timeout:", err.message);
}

💾 File Uploads & Downloads

// Upload
const form = new FormData();
form.append("file", myFile);
await api.post("/upload", form, {
  headers: { "Content-Type": "multipart/form-data" },
});

// Download
const res = await api.get("/file.pdf", { responseType: "blob" });
const blob = res.data;

🛑 Request Cancellation

const controller = new AbortController();

const req = api.get("/posts", { signal: controller.signal });
setTimeout(() => controller.abort(), 1000);

try {
  await req;
} catch (err) {
  console.log("❌ Cancelled:", err.name);
}

⚛️ React Example

import React, { useEffect, useState } from "react";
import { client } from "tiny-http";

export function Posts() {
  const [posts, setPosts] = useState<any[]>([]);

  useEffect(() => {
    const controller = new AbortController();

    client
      .get("/posts", { signal: controller.signal })
      .then((res) => setPosts(res.data))
      .catch((err) => {
        if (err.name !== "AbortError") console.error("Fetch failed:", err);
      });

    return () => controller.abort();
  }, []);

  return (
    <ul>
      {posts.slice(0, 5).map((p) => (
        <li key={p.id}>{p.title}</li>
      ))}
    </ul>
  );
}

⚙️ Configuration Options

| Option | Type | Description | |--------|------|-------------| | baseURL | string | Base API URL | | timeout | number | Request timeout (ms) | | headers | Record<string,string> | Default headers | | retry.attempts | number | Retry count | | retry.backoff | "fixed" or "exponential" | Retry delay type | | retry.delay | number | Base retry delay (ms) | | cache | RequestCache | "default", "no-store", "reload", etc. | | responseType | "json", "text", "blob", "arraybuffer" | Expected response data type |


🧠 Features Summary

✅ Works in both Node.js and Browser
✅ Zero dependencies
✅ TypeScript-first design
✅ Built-in retry & timeout
✅ Interceptors (request, response, error)
✅ Abortable requests
✅ Supports JSON, Blob, and FormData


📄 License

MIT © 2025
Created with ❤️ by developers who love clean HTTP clients.