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

vmo-request

v0.0.8

Published

axios request http https

Downloads

195

Readme

vmo-request

VmoRequest is a request utility class based on Axios, designed to provide features such as caching, state management, and configuration merging. It is particularly suitable for scenarios where the same requests need to be frequently made in an application, as the caching mechanism can effectively reduce server load and improve application performance.

Features

  • Caching Mechanism: By hashing request configurations with MD5, it caches request results to avoid duplicate requests.
  • Retry Mechanism: To handle network or API instability, you can set a retry mechanism to improve request success rates.
  • State Management: It supports three state management options: PENDING, FULFILLED, and REJECTED, ensuring consistency in request states.
  • Configuration Merging: It merges default configurations with user configurations using the mergeDeepRight method to prevent configuration overriding issues.
  • Expiration Time: It supports setting cache expiration times, automatically clearing expired caches.

Installation

npm install axios ramda md5

Usage Example

import VmoRequest from './VmoRequest'
import axios from 'axios'

const vmoRequest = new VmoRequest({
  baseURL: 'https://api.example.com',
  headers: {
    'Content-Type': 'application/json'
  }
})

async function fetchData() {
  try {
    const response = await vmoRequest.request(
      {
        url: '/data',
        method: 'get'
      },
      1000 * 2, // Cache for 2 seconds
      3 // Retry 3 times, total 4 requests
    )
    console.log(response.data)
  } catch (error) {
    console.error(error)
  }
}
fetchData() // Initiate the request
fetchData() // Enter the waiting queue
fetchData() // Enter the waiting queue
fetchData() // Enter the waiting queue
setTimeout(() => {
  fetchData() // Enter the waiting queue or directly get the cached result if the data has been returned
}, 1000 * 1)
// In the end, only one request will be truly initiated. If it fails, it will retry 3 times. When the result is finally returned, it will be distributed to subsequent requests.

setTimeout(() => {
  fetchData() // The cache will expire and a new request will be initiated
}, 1000 * 10)

API Documentation

VmoRequest Class Constructor

const vmoRequest = new VmoRequest({
  baseURL: 'https://api.example.com',
  headers: {
    'Content-Type': 'application/json'
  }
})
console.log(!!vmRequest.instance) // false

// Build mode for generating instances
const vmoRequest = new VmoRequest(
  {
    baseURL: 'https://api.example.com',
    headers: {
      'Content-Type': 'application/json'
    }
  },
  true
)
console.log(!!vmRequest.instance) // true

vmoRequest.instance // The created axios instance
  • new VmoRequest(config, createInstance) Parameters:
    • config: Default configuration.
    • createInstance: Boolean indicating whether to create an accompanying axios instance, default is false.

getDefaultConfig Method

vmoRequest.getDefaultConfig() // Partial<AxiosRequestConfig>
  • Return Value:
    • Returns the current default configuration.。

setDefaultConfig Method

vmoRequest.setDefaultConfig(config: Partial<AxiosRequestConfig>): boolean
  • Parameters:
    • config: The new default configuration.
  • Return Value:
    • Returns true if the configuration update is successful.。

request Method

vmoRequest.request(config: Partial<AxiosRequestConfig>, expiredTime: number = 0, retryTimes:number=0): Promise<any>
  • Parameters:
    • config: User’s Axios configuration.
    • expiredTime: Cache expiration time (in milliseconds), default is 0 (no caching). However, requests initiated in the same event loop will still be merged, unless set to -1, in which case they will be treated as normal requests to handle certain special scenarios.
    • retryTimes: Number of retries, default is 0 (no retries).
  • Return Value:
    • Returns a Promise that resolves to the request response data or rejects with error data.