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 🙏

© 2025 – Pkg Stats / Ryan Hefner

laziness-axios

v1.0.1

Published

🚀 Axios Lazy – Một wrapper Axios không cần thiết lập, có đầy đủ kiểu dữ liệu dành cho các nhà phát triển lười biếng. Phiên bản được cấu hình sẵn, bộ chặn tích hợp sẵn và xuất kiểu dữ liệu hoàn chỉnh. Chỉ cần nhập và chờ.😎

Readme

Lazy Axios for lazy people

🚀 Axios Lazy – Một wrapper Axios không cần thiết lập, có đầy đủ kiểu dữ liệu dành cho các nhà phát triển lười biếng. Phiên bản được cấu hình sẵn, bộ chặn tích hợp sẵn và xuất kiểu dữ liệu hoàn chỉnh. Chỉ cần nhập và chờ.😎

Axios Lazy là một thư viện “kế thừa Axios" dành cho những lập trình viên lười (nhưng thông minh).

Chỉ cần cài đặt và import – bạn sẽ có ngay:

  • ⚙️ Một Axios instance cấu hình sẵn với baseURL, timeout, và interceptor.
  • 🔁 Tự động xử lý token, request/response interceptors.
  • 🧩 Tích hợp đầy đủ type của Axios (AxiosResponse, AxiosError, v.v.).
  • 💤 Không cần setup gì thêm — chỉ cần import và dùng.
import { httpRequest } from "lazy-axios";

export const instance = httpRequest({
  config: {
    authType: "none",
    baseURL: "https://your-api-base-url.com",
    headers_parameters: {
      "key": "value",
    },
  },
});

Interceptors Features

* Tự động xử lý token trong header.
* Cấu hình request interceptors tùy chỉnh của bạn hoặc dùng mặc định đã cấu hình sẵn.
* Cấu hình response success interceptors tùy chỉnh của bạn hoặc dùng mặc định đã cấu hình sẵn.
* Cấu hình response error interceptors tùy chỉnh của bạn hoặc dùng mặc định đã cấu hình sẵn, và đang hỗ trợ các error sau.
  - Lỗi khi server có quá nhiều request vào (429 Too Many Requests).
  - Lỗi khi bạn không quyền lấy tài nguyên (403 Forbidden).
  - Lỗi khi bạn không có quyền truy cập vào tài nguyên (401 Unauthorized).
  - Đang update thêm các lỗi khác.

Installation

Package manager

Using npm:

npm install axios

Using yarn:

yarn add axios

Using pnpm

pnpm add axios

Once the package is installed, you can import the library using import or require approach.

For ES6 modules:

import axios, { httpRequest } from "lazy-axios";

For CommonJS modules:

const axios = require("lazy-axios");
const { httpRequest } = require("lazy-axios");
const instance = httpRequest({
  config: {
    authType: "none",
    baseURL: "https://dyour-api-base-url.com",
    headers_parameters: {
      "key": "value",
    },
  },
  interceptors: {
    response: {},
    request: {},
  },
  token: "123456",
});

Chi tiết thuộc tính

Request Config

Kế thừa tất cả thuộc tính từ Axios

Ngoài ra tôi còn support thêm các thuộc tính sau:

  config: {
    authType: "none",
    baseURL: "https://dyour-api-base-url.",
    headers_parameters: {
      "client-id": "test_client_id",
      "client-secret": "test_client_secret",
    },
  },

  // Loại xác thực default là "none"
  authType: "bearer" | "basic" | "api_key" | "none";

  // Content-Type header default là "application/json"
  contentType?: string;

  // Accept header default là "application/json"
  acceptHeader?: string;

  // Your custom headers
  // Example: { "X-Custom-Header": "value" }
  headers_parameters: {
    [k: string]: string;
  };

Interceptors Config

Kế thừa tất cả thuộc tính từ Axios

Và tôi đã phát triển các tính năng về request, response interceptors, và bộ xử lý lỗi (forbidden, unauthorized, too many requests).

Cách dùng như sau:

 interceptors: {
    // Your custom Response Interceptors with AxiosResponse
    response: {
      // Case error
      error: {
        manyRequest: {
          args: {
            retries: 3,
            delayMs: 1100,
          },
          functions: async ({ ...args }) => {
            Your custom function here
          },
        },
        forbidden: {
          args: {
            redirect_url: "/403",
          },
          functions: async ({ ...args }) => {
            Your custom function here
          },
        },
        unauthorized: {
          args: {
            redirect_url: "/login",
          },
          functions: async ({ ...args }) => {
            Your custom function here
          },
        },
      },
      // Case success
      success: () => {
          Your custom function here
      },
    },
    // Your custom Request Interceptors
    request: {
      "key": "value",
    },
  }

Chi tiết thuộc tính

interceptors: {
  // Your custom Request Interceptors with AxiosRequestConfig
  request: {
    "key": "value",
  },
  // Your custom Response Interceptors with AxiosResponse
  response:{
    // Your custom Error Interceptors with AxiosError
    error:{},
    // Your custom Success Interceptors with AxiosResponse
    success:()=>{},
  }
}
interceptors: {
  response:{
    // Your custom Success Interceptors with AxiosResponse
    success:()=>{
      // Your custom function here
    },
  }
}

Case many request with status 429 Too Many Requests

interceptors: {
  response:{
    // Your custom Error Interceptors with AxiosError
    error:{
      manyRequest: {
          args: {
            retries: 3,
            delayMs: 1100,
          },
        },
    },
  }
}



// argument for config
args?: {
    /**
     * Config of request
     */
    config?: AxiosRequestConfig;
    /**
     * Number of retries
     */
    retries?: number;
    /**
     * Delay between retries in milliseconds
     */
    delayMs?: number;
    /**
     * Instance of axios
     */
    instance?: AxiosInstance;
}

// Function to handle your logic many request error
functions?: ({ ...params }: args) => MaybePromise<AxiosResponse<any>>;

Case status 401 Authentication request rejected or invalid

interceptors: {
  response:{
    // Your custom Error Interceptors with AxiosError
    error:{
      unauthorized: {
          args: {
            retries: 3,
            delayMs: 1100,
          },
        },
    },
  }
}



// argument for config
args?: {
    /**
     * Redirect url when unauthorized
     */
    redirect_url?: string;
    /**
     * Url of request
     */
    url?: string;
    /**
     * Method of request
     */
    method?: string;
}

// Function to handle your logic unauthorized error
functions?: ({ ...params }: args) => MaybePromise<void>;

Case status 403 You no longer have access to system resources.

interceptors: {
  response:{
    // Your custom Error Interceptors with AxiosError
    error:{
      unauthorized: {
          args: {
            retries: 3,
            delayMs: 1100,
          },
        },
    },
  }
}



// argument for config
args?: {
    /**
     * Redirect url when unauthorized
     */
    redirect_url?: string;
    /**
     * Url of request
     */
    url?: string;
    /**
     * Method of request
     */
    method?: string;
}

// Function to handle your logic forbidden error
functions?: ({ ...params }: args) => MaybePromise<void>;

Những trường hợp lỗi đang phát triển và sẽ phát hành trong tương lai

status 404 Couldn't find the resource you needed?
notFound()

 status 409 is in conflict with server resources
conflict()

status 422 Missing required field, or invalid data.()
unprocessable

status > 500 error from server
serverError()