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

sim-fetchx

v1.0.4

Published

simplified fetch api , use http requests in a simple way

Downloads

31

Readme

API Documentation

SimFetchX is a lightweight 🚀, configurable ⚙️, and retry-enabled 🔄 HTTP client for making API requests. It supports caching 💾, retries 🔄, timeouts ⏳, and streaming 🌊, making it ideal for handling unreliable network conditions 📶 and large data transfers.


Table of Contents

  1. Installation
  2. Usage
  3. API Methods
  4. Examples
  5. License

Installation ✳️

To use SimFetchX, install it via npm:

npm install sim-fetchx

Usage

Run test within the the lib folder npm test

Initialization ✳️

To start using SimFetchX, create an instance by passing a configuration object.

import { SimFetchX } from 'sim-fetchx';

const api = new SimFetchX({
  baseUrl: 'https://api.example.com',
  timeout: 5000, // Optional: Default timeout is 5 seconds
  retry: true,   // Optional: Enable retries (default is true)
  retryNumber: 3, // Optional: Number of retries (default is 5)
  cacheTtl: 60000, // Optional: Cache TTL in milliseconds (default is 1 minute)
});

Making Requests ✳️

Use the available methods (get, post, put, delete, etc.) to make HTTP requests.

Caching

Responses are cached for 1 minute (default) to reduce redundant requests. You can clear the cache using clearCache().

Retries

If a request fails due to a server error (5xx) or timeout, SimFetchX will automatically retry the request up to the specified number of times.

Streaming ✳️

SimFetchX supports streaming large responses using the stream() method. This is useful for downloading files or processing data in chunks.

Error Handling

SimFetchX provides detailed error handling, including status codes, error messages, and retry logic.


API Methods 🕹️

get

Makes a GET request.

async get(path: string, options?: IOption): Promise<Response>

Example:

const response = await api.get('/users');
const data = await response.json();

post

Makes a POST request.

async post<T>(path: string, data: any | Record<string, any>, options?: IOption): Promise<Response>

Example:

const response = await api.post('/users', { name: 'John Doe' });
const result = await response.json();

put

Makes a PUT request.

async put<T>(path: string, data: any | Record<string, any>, options?: IOption): Promise<Response>

Example:

const response = await api.put('/users/1', { name: 'Jane Doe' });
const result = await response.json();

delete

Makes a DELETE request.

async delete(path: string, options?: IOption): Promise<Response>

Example:

const response = await api.delete('/users/1');

json

Makes a request and parses the response as JSON.

async json<T>(path: string, options?: Record<string, any>): Promise<T>

Example:

const data = await api.json<User[]>('/users');

text

Makes a request and parses the response as text.

async text(path: string, options?: Record<string, any>): Promise<string>

Example:

const text = await api.text('/document');

blob

Makes a request and parses the response as a Blob.

async blob(path: string, options?: Record<string, any>): Promise<Blob>

Example:

const blob = await api.blob('/image');

arrayBuffer

Makes a request and parses the response as an ArrayBuffer.

async arrayBuffer(path: string, options?: Record<string, any>): Promise<ArrayBuffer>

Example:

const buffer = await api.arrayBuffer('/file');

stream

Makes a request and returns a ReadableStream for streaming large responses.

async stream(path: string, options?: Record<string, any>): Promise<ReadableStream>

Example:

const stream = await api.stream('/large-file');
const reader = stream.getReader();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  console.log('Received chunk:', value);
}

clearCache

Clears the cache.

clearCache(): void

Example:

api.clearCache();

Examples

Example 1: Fetching Data with Retries

const api = new SimFetchX({
  baseUrl: 'https://api.example.com',
  retry: true,
  retryNumber: 3,
});

try {
  const response = await api.get('/users');
  const users = await response.json();
  console.log(users);
} catch (error) {
  console.error('Request failed:', error);
}

Example 2: Caching Responses

const api = new SimFetchX({
  baseUrl: 'https://api.example.com',
});

// First request (not cached)
const response1 = await api.get('/posts');
const posts1 = await response1.json();

// Second request (cached)
const response2 = await api.get('/posts');
const posts2 = await response2.json();

console.log(posts1 === posts2); // true

Example 3: Uploading Data

const api = new SimFetchX({
  baseUrl: 'https://api.example.com',
});

const response = await api.post('/upload', { file: 'data' }, {
  headers: {
    'Content-Type': 'application/json',
  },
});

console.log(await response.json());

Example 4: Streaming Large Files

const api = new SimFetchX({
  baseUrl: 'https://api.example.com',
});

const stream = await api.stream('/large-file');
const reader = stream.getReader();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  console.log('Received chunk:', value);
}

Example 5: Error Handling

const api = new SimFetchX({
  baseUrl: 'https://api.example.com',
  retry: true,
  retryNumber: 3,
});

try {
  const response = await api.get('/nonexistent-endpoint');
  const data = await response.json();
} catch (error) {
  if (error.status === 404) {
    console.error('Resource not found');
  } else {
    console.error('Request failed:', error.message);
  }
}

credits to: user: https://github.com/Kanekivly & user: https://github.com/Anoncomrade993 __

License

This project is licensed under the MIT License 🔐. See the [LICENSE](LICENSE) file for details.