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

luhanxin-http-utils

v1.0.5

Published

Enterprise-level HTTP SDK with multi-client, chain of responsibility, cross-end adapter

Downloads

698

Readme

HTTP Utils

A cross-platform HTTP client library for Web, MiniProgram (WeChat), React Native, Electron, and Node.js environments.

Features

  • Unified API: Same API across different JavaScript environments
  • Adapter-based: Plugable adapters for different platforms
  • Middleware chains: Request, response, and error middleware chains
  • Interceptor support: Easy-to-use interceptor methods
  • Cache & Debounce: Built-in request caching and debouncing
  • Retry & Timeout: Automatic retry with configurable delay
  • TypeScript: Fully typed with TypeScript

Installation

npm install luhanxin-http-utils
# or
pnpm add luhanxin-http-utils

Quick Start

import { RequestClient, ClientManager } from 'http-utils';

// Create a client
const client = new RequestClient('my-client', 'https://api.example.com');

// Add interceptors
client.useRequestInterceptor(async (ctx, next) => {
  console.log(`Sending ${ctx.config.method} request to ${ctx.fullUrl}`);
  ctx.config.headers['Authorization'] = 'Bearer token';
  await next();
});

client.useResponseInterceptor(async (ctx, next) => {
  await next();
  console.log(`Received response: ${ctx.response?.status}`);
});

// Make requests
const posts = await client.get('/posts');
const newPost = await client.post('/posts', { title: 'Hello' });

// Register client for global access
ClientManager.register(client);
const defaultClient = ClientManager.getDefault();

Configuration

const config = {
  domain: 'https://api.example.com',
  timeout: 10000,          // Request timeout in ms
  retry: 3,                // Number of retries
  retryDelay: 1000,        // Delay between retries in ms
  cache: true,             // Enable caching (GET requests only)
  debounce: 300,           // Debounce time in ms
  responseType: 'json',    // 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData'
  headers: {               // Default headers
    'Content-Type': 'application/json',
  },
};

Supported Environments

  • Web: Uses Fetch API
  • WeChat MiniProgram: Uses wx.request
  • React Native: Uses Fetch API
  • Electron: Uses Fetch API
  • Node.js: Uses http/https modules (NodeAdapter)

The library automatically detects the environment and selects the appropriate adapter.

Advanced Usage

Multiple Clients

const apiClient = new RequestClient('api', 'https://api.example.com');
const authClient = new RequestClient('auth', 'https://auth.example.com');

ClientManager.register(apiClient);
ClientManager.register(authClient);

const client = ClientManager.get('api');

Sub-clients

const mainClient = new RequestClient('main', 'https://api.example.com');
const postsClient = mainClient.createSubClient('posts');
// postsClient inherits middleware and configuration from mainClient

Custom Adapters

Implement the Adapter interface and use AdapterFactory.setEnvironment() to override.

Error Handling

try {
  await client.get('/protected');
} catch (error) {
  if (error.status === 401) {
    // Handle unauthorized
  }
}

API Reference

RequestClient

  • new RequestClient(name, domain, defaultConfig)
  • request(config): Promise<Response>
  • get(url, params, config)
  • post(url, data, config)
  • put(url, data, config)
  • delete(url, config)
  • withConfig(config): this
  • withDomain(domain): this
  • useRequestInterceptor(fn): this
  • useResponseInterceptor(fn): this
  • useErrorInterceptor(fn): this
  • createSubClient(name, config): RequestClient

ClientManager

  • register(client): void
  • get(name): RequestClient | undefined
  • getDefault(): RequestClient

AdapterFactory

  • getAdapter(): Adapter
  • setEnvironment(env): void
  • getEnvironment(): EnvType

Building

pnpm install
pnpm build

License

MIT