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

@leyton/request

v10.0.0

Published

A request library based on axios, for web and uni-app.

Readme

@leyton/request

A powerful, strictly typed HTTP client based on Axios, designed for Web and UniApp (WeChat MiniProgram) environments.

Features

  • 🚀 Multi-Platform: Seamlessly works in Browser and UniApp/WeChat MiniProgram.
  • 🔒 Type Safe: Full TypeScript support with generic response types.
  • 🛡️ Interceptor: Built-in token injection and error handling.
  • ⚡ Optimization: Automatic request deduplication and cancellation.
  • 📂 File Upload: Simplified upload method.

Installation

pnpm add @leyton/request

Usage

1. Basic Setup

Create an instance of HttpClient:

import HttpClient, { HttpClientConfig } from '@leyton/request';

const config: HttpClientConfig = {
  baseURL: 'https://api.example.com',
  timeout: 10000,
  tokenStorageKey: 'auth_token', // Key in localStorage
  onUnauthorized: () => {
    // Redirect to login page
    console.log('Token expired, please login.');
    window.location.href = '/login';
  },
  onError: (err) => {
    console.error('Global error handler:', err.message);
  }
};

export const client = new HttpClient(config);

2. Making Requests

interface User {
  id: number;
  name: string;
}

// GET Request
async function getUser(id: number) {
  try {
    const user = await client.get<User>(`/users/${id}`);
    console.log(user.name);
  } catch (error) {
    console.error(error);
  }
}

// POST Request
async function createUser(data: { name: string }) {
  const newUser = await client.post<User>('/users', data);
  return newUser;
}

3. File Upload

async function uploadAvatar(file: File) {
  const result = await client.upload<{ url: string }>('/upload', file, 'avatar');
  console.log('Uploaded:', result.url);
}

4. Cancellation

Requests are automatically cancelled if a duplicate request (same URL, method, params) is initiated while the previous one is pending. You can also manually cancel requests.

client.cancelAllRequests();

5. UniApp / MiniProgram Support

The library automatically detects the environment. If running in UniApp or WeChat MiniProgram, it switches to the internal adapter using uni.request or wx.request.

No extra configuration is needed!

API

HttpClient

Constructor

new HttpClient(config: HttpClientConfig)

Methods

  • request<T>(url, config): Promise<T>
  • get<T>(url, params?, config?): Promise<T>
  • post<T>(url, data?, config?): Promise<T>
  • put<T>(url, data?, config?): Promise<T>
  • delete<T>(url, params?, config?): Promise<T>
  • patch<T>(url, data?, config?): Promise<T>
  • upload<T>(url, file, fieldName?, config?): Promise<T>
  • cancelAllRequests(message?)

HttpClientConfig

| Property | Type | Description | |Data | --- | --- | | baseURL | string | Base URL for API | | timeout | number | Request timeout (ms) | | tokenStorageKey | string | LocalStorage key for token | | getToken | () => string \| Promise<string> | Custom token retrieval | | onUnauthorized | () => void | 401 callback | | onError | (err: ApiError) => void | Global error callback |