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

@ked3/http-client

v1.0.3

Published

TypeScript network request library supporting fetch and xhr

Readme

This is a TypeScript HTTP request library designed based on the dependency inversion principle, supporting the use of Fetch API or XMLHttpRequest at the underlying layer.

license Awesome

English | 简体中文

Features

  • 🔄 Dependency Inversion Design - High-level modules do not depend on specific implementations of low-level modules
  • 🔌 Pluggable Engines - Supports Fetch API and XMLHttpRequest
  • 🔧 Flexible Configuration - Rich request configuration options
  • 🔗 Interceptor Support - Can intercept requests and responses for custom processing
  • 📦 Type Safety - Written in TypeScript, providing complete type definitions

Installation

npm install http-client

Usage

Basic Usage

import HttpClientFactory from 'http-client';

// Create HTTP client (uses Fetch engine by default)
const httpClient = HttpClientFactory.create();

// Send GET request
httpClient.get('https://api.example.com/users')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

// Send POST request
httpClient.post('https://api.example.com/users', {
  name: 'Zhang San',
  email: '[email protected]'
})
  .then(response => {
    console.log(response.data);
  });

Selecting an Engine

// Use Fetch API engine
const fetchClient = HttpClientFactory.createFetch();

// Use XMLHttpRequest engine
const xhrClient = HttpClientFactory.createXhr();

// Or select through parameters
const client = HttpClientFactory.create('xhr'); // 'fetch' or 'xhr'

Configuring Requests

// Set default configuration
const httpClient = HttpClientFactory.create('fetch', {
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your-api-key'
  },
  timeout: 5000,
  withCredentials: true
});

// Configuration for specific requests
httpClient.get('https://api.example.com/posts', {
  params: { // URL query parameters
    page: 1,
    limit: 10
  },
  headers: {
    'X-Custom-Header': 'value'
  }
});

Using Interceptors

const httpClient = HttpClientFactory.create('fetch', {
  // Request interceptor
  requestInterceptor: (config) => {
    // Add authentication header before sending request
    return {
      ...config,
      headers: {
        ...config.headers,
        'Authorization': `Bearer ${getToken()}`
      }
    };
  },
  
  // Response interceptor
  responseInterceptor: (response) => {
    // Can handle responses uniformly
    if (response.status >= 400) {
      handleError(response);
    }
    return response;
  }
});

API Reference

HttpClientFactory

  • create(engineType?: 'fetch' | 'xhr', defaultConfig?: Partial<HttpRequestConfig>): HttpClient
  • createFetch(defaultConfig?: Partial<HttpRequestConfig>): HttpClient
  • createXhr(defaultConfig?: Partial<HttpRequestConfig>): HttpClient

HttpClient

  • request<T = any>(config: HttpRequestConfig): Promise<HttpResponse<T>>
  • get<T = any>(url: string, config?: Partial<HttpRequestConfig>): Promise<HttpResponse<T>>
  • post<T = any>(url: string, data?: any, config?: Partial<HttpRequestConfig>): Promise<HttpResponse<T>>
  • put<T = any>(url: string, data?: any, config?: Partial<HttpRequestConfig>): Promise<HttpResponse<T>>
  • delete<T = any>(url: string, config?: Partial<HttpRequestConfig>): Promise<HttpResponse<T>>
  • patch<T = any>(url: string, data?: any, config?: Partial<HttpRequestConfig>): Promise<HttpResponse<T>>

HttpRequestConfig

interface HttpRequestConfig {
  url: string;
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
  headers?: Record<string, string>;
  params?: Record<string, any>;
  body?: any;
  timeout?: number;
  withCredentials?: boolean;
  responseType?: 'json' | 'text' | 'blob' | 'arraybuffer' | 'formdata';
  requestInterceptor?: (config: HttpRequestConfig) => HttpRequestConfig;
  responseInterceptor?: <T>(response: HttpResponse<T>) => HttpResponse<T>;
}

HttpResponse

interface HttpResponse<T = any> {
  data: T;
  status: number;
  statusText: string;
  headers: Record<string, string>;
  originalResponse?: any;
}

License

MIT