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

fetchquery

v1.0.7

Published

Lightweight JavaScript library for simplified HTTP requests with built-in caching and async support.

Downloads

25

Readme

fetchQuery

fetchQuery is a lightweight JavaScript library designed to simplify and optimize HTTP requests. It is ideal for web applications and API integrations, offering asynchronous operations and built-in caching for enhanced performance.

Key Features

  • Asynchronous Operations: Utilizes modern async/await syntax for non-blocking HTTP requests.
  • Caching: Automatically caches GET request responses to reduce network calls and speed up subsequent requests.
  • Custom Headers and Body: Supports custom headers and request bodies across all HTTP methods.
  • Minimal Dependencies: Designed to be lightweight with minimal external dependencies.
  • Intuitive API: Familiar and easy-to-use interface, inspired by popular HTTP clients like Axios.
  • Browser Compatible: Works seamlessly across all modern browsers supporting the Fetch API.

Installation

Install fetchQuery using your preferred package manager:

npm install fetchquery

Usage

Basic Asynchronous GET Request

import fetchQuery from 'fetchquery'

async function fetchData() {
  try {
    const data = await fetchQuery.get(
      'https://jsonplaceholder.typicode.com/todos/1',
    )
    console.log(data)
  } catch (error) {
    console.error('Error fetching data:', error)
  }
}

fetchData()

GET Request with Custom Headers

const headers = {
  Authorization: 'Bearer your-token',
  'Custom-Header': 'value',
}

async function fetchDataWithHeaders() {
  try {
    const data = await fetchQuery.get(
      'https://jsonplaceholder.typicode.com/todos/1',
      headers,
    )
    console.log(data)
  } catch (error) {
    console.error('Error:', error)
  }
}

fetchDataWithHeaders()

POST Request with Body and Headers

const postData = {
  title: 'New Todo',
  completed: false,
}

const headers = {
  Authorization: 'Bearer your-token',
  'Content-Type': 'application/json',
}

async function createTodo() {
  try {
    const data = await fetchQuery.post(
      'https://jsonplaceholder.typicode.com/todos',
      postData,
      headers,
    )
    console.log(data)
  } catch (error) {
    console.error('Error:', error)
  }
}

createTodo()

Caching GET Requests

fetchQuery automatically caches GET responses to avoid redundant network calls:

async function fetchDataWithCache() {
  try {
    const data1 = await fetchQuery.get(
      'https://jsonplaceholder.typicode.com/todos/1',
    )
    console.log('First Fetch:', data1)

    // This will use the cached data
    const data2 = await fetchQuery.get(
      'https://jsonplaceholder.typicode.com/todos/1',
    )
    console.log('From Cache:', data2)
  } catch (error) {
    console.error('Error:', error)
  }
}

fetchDataWithCache()

Custom Cache Expiration

Modify the default cache expiration time (default is 1 hour):

// Set cache expiration time in milliseconds
fetchQuery.setCacheExpirationTime(30 * 60 * 1000) // 30 minutes

API Reference

Methods

  • get(url, headers) - Sends a GET request.

    • url: The request URL.
    • headers: Optional custom headers.
  • post(url, data, headers) - Sends a POST request.

    • url: The request URL.
    • data: Request body.
    • headers: Optional custom headers.
  • put(url, data, headers) - Sends a PUT request.

  • patch(url, data, headers) - Sends a PATCH request.

  • delete(url, data, headers) - Sends a DELETE request.

Cache Configuration

  • Cache Expiration: Default is 1 hour. Configurable via setCacheExpirationTime().
  • Bypassing Cache: Pass { skipCache: true } to force a new request.

Contributing

We welcome contributions! To contribute:

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

Please follow our contributing guidelines and coding standards.

License

fetchQuery is licensed under the MIT License.

Credits

Inspired by the Fetch API and libraries like Axios to deliver a seamless HTTP request experience.