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

@alok5953/tiny-http-client

v1.0.1

Published

A lightweight, universal HTTP client wrapping native fetch API with zero dependencies

Downloads

25

Readme

@alok5953/tiny-http-client

npm version License: MIT Node.js Version

A modern, lightweight HTTP client that wraps the native fetch API for both browser and Node.js environments. Built with modern JavaScript practices and zero dependencies.

Why Choose This Library?

  • 🪶 Truly Lightweight: Zero dependencies, tiny bundle size (~2KB minified + gzipped)
  • ⚡️ Modern & Fast: Built on native fetch API
  • 🔄 Smart Retries: Built-in retry mechanism with exponential backoff
  • Timeout Control: Automatic request timeouts using AbortController
  • 🔌 Extensible: Plugin system for custom functionality
  • 🌐 Universal: Works in both browser and Node.js (≥18)
  • 🛡️ Type-Safe: Written in JavaScript with JSDoc comments for TypeScript support

Installation

npm install @alok5953/tiny-http-client

Quick Start

import http from '@alok5953/tiny-http-client';

// Simple GET request with automatic JSON parsing
const users = await http.get('https://api.example.com/users');

// POST with JSON body
const newUser = await http.post('/api/users', {
  name: 'John Doe',
  email: '[email protected]'
});

// Custom instance with advanced configuration
const api = new HttpClient('https://api.example.com', {
  timeout: 5000,
  retries: 3,
  retryDelay: 1000,
  headers: {
    'Accept': 'application/json'
  }
});

Features

Automatic Retries

// Retry failed requests automatically
const api = new HttpClient('https://api.example.com', {
  retries: 3,           // Number of retry attempts
  retryDelay: 1000      // Base delay (uses exponential backoff)
});

// The client will automatically retry failed requests
// with increasing delays: 1s, 2s, 4s
const data = await api.get('/unstable-endpoint');

Plugin System

import { authPlugin, cachePlugin, loggingPlugin } from '@alok5953/tiny-http-client/plugins';

// Authentication plugin
http.use(authPlugin('your-token'));

// Caching plugin with TTL
http.use(cachePlugin(60000)); // 1 minute cache

// Logging plugin
http.use(loggingPlugin());

// Custom plugin
http.use(client => {
  const originalRequest = client.request.bind(client);
  client.request = async (url, options) => {
    console.log(`Request to: ${url}`);
    const response = await originalRequest(url, options);
    console.log(`Response status: ${response.status}`);
    return response;
  };
});

API Reference

HttpClient

// Constructor
new HttpClient(baseUrl?: string, options?: HttpClientOptions)

// Instance methods
request(url: string, options?: RequestOptions): Promise<any>
get(url: string, options?: RequestOptions): Promise<any>
post(url: string, data?: any, options?: RequestOptions): Promise<any>
put(url: string, data?: any, options?: RequestOptions): Promise<any>
delete(url: string, options?: RequestOptions): Promise<any>
use(plugin: Plugin): HttpClient

Options

interface HttpClientOptions {
  timeout?: number;        // Request timeout in ms (default: 10000)
  retries?: number;        // Number of retry attempts (default: 0)
  retryDelay?: number;     // Base delay between retries in ms (default: 1000)
  headers?: Headers;       // Default headers for all requests
  parseJson?: boolean;     // Auto-parse JSON responses (default: true)
  [key: string]: any;      // Any valid fetch options
}

Error Handling

try {
  const data = await http.get('/api/users');
} catch (error) {
  if (error.name === 'HttpError') {
    console.error(`HTTP ${error.status}:`, error.message);
    // Access the original response
    console.error('Response:', error.response);
  } else if (error.name === 'TimeoutError') {
    console.error(`Request timed out after ${error.timeout}ms`);
  }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development

# Install dependencies
npm install

# Run tests
npm test

# Lint code
npm run lint

# Format code
npm run format

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Alok

Acknowledgments

  • Inspired by the need for a lightweight, modern HTTP client
  • Built with modern JavaScript features and best practices
  • Zero dependencies for minimal bundle size and maximum reliability