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

@rutansh0101/fetchify

v1.0.5

Published

A modern, lightweight HTTP client library built on top of the native Fetch API with axios-like interface, interceptors, and timeout support

Readme

Fetchify - A Lightweight HTTP Client Library

npm version npm downloads license

A modern, lightweight HTTP client library built on top of the native Fetch API. It provides a clean, axios-like interface with support for interceptors, request/response transformation, and timeout handling.


Installation

npm install @rutansh0101/fetchify

Quick Start

import fetchify from '@rutansh0101/fetchify';

// Create an instance
const api = fetchify.create({
    baseURL: 'https://api.example.com',
    timeout: 5000,
    headers: {
        'Content-Type': 'application/json'
    }
});

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

Features

Axios-like API - Familiar and easy to use
Request/Response Interceptors - Transform requests and responses
Timeout Support - Abort requests after specified duration
Configuration Merging - Instance, request-level, and default configs
All HTTP Methods - GET, POST, PUT, PATCH, DELETE
Lightweight - ~5KB with zero dependencies


Basic Usage

Making Requests

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

// POST request
await api.post('/users', {
    body: JSON.stringify({ name: 'John', email: '[email protected]' })
});

// PUT request
await api.put('/users/1', {
    body: JSON.stringify({ name: 'Jane Doe' })
});

// PATCH request
await api.patch('/users/1', {
    body: JSON.stringify({ email: '[email protected]' })
});

// DELETE request
await api.delete('/users/1');

Request Configuration

Override default settings per request:

const response = await api.get('/users', {
    timeout: 10000,
    headers: {
        'Authorization': 'Bearer token123'
    }
});

Interceptors

Request Interceptors

Modify requests before they are sent:

api.addRequestInterceptor(
    (config) => {
        // Add authentication token
        const token = localStorage.getItem('authToken');
        config.config.headers['Authorization'] = `Bearer ${token}`;
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

Response Interceptors

Handle responses globally:

api.addResponseInterceptor(
    (response) => {
        // Handle unauthorized responses
        if (response.status === 401) {
            window.location.href = '/login';
        }
        return response;
    },
    (error) => {
        console.error('Request failed:', error);
        return Promise.reject(error);
    }
);

Advanced Examples

Complete Setup with Authentication

import fetchify from '@rutansh0101/fetchify';

const api = fetchify.create({
    baseURL: 'https://api.example.com',
    timeout: 5000,
    headers: {
        'Content-Type': 'application/json'
    }
});

// Add auth token to all requests
api.addRequestInterceptor((config) => {
    const token = localStorage.getItem('token');
    if (token) {
        config.config.headers['Authorization'] = `Bearer ${token}`;
    }
    return config;
});

// Handle errors globally
api.addResponseInterceptor(
    (response) => {
        if (!response.ok) {
            throw new Error(`HTTP ${response.status}: ${response.statusText}`);
        }
        return response;
    },
    (error) => {
        if (error.message.includes('timeout')) {
            alert('Request timed out. Please try again.');
        }
        return Promise.reject(error);
    }
);

// Use the API
async function fetchUsers() {
    try {
        const response = await api.get('/users');
        const users = await response.json();
        console.log(users);
    } catch (error) {
        console.error('Failed to fetch users:', error);
    }
}

Multiple API Instances

const mainAPI = fetchify.create({
    baseURL: 'https://api.example.com',
    timeout: 5000
});

const authAPI = fetchify.create({
    baseURL: 'https://auth.example.com',
    timeout: 10000
});

// Use independently
await mainAPI.get('/users');
await authAPI.post('/login', { body: credentials });

Error Handling

try {
    const response = await api.get('/users', { timeout: 3000 });
    
    if (!response.ok) {
        throw new Error(`HTTP ${response.status}`);
    }
    
    const data = await response.json();
    return data;
    
} catch (error) {
    if (error.message.includes('timeout')) {
        console.error('Request timed out');
    } else {
        console.error('Request failed:', error);
    }
}

API Reference

fetchify.create(config)

Creates a new Fetchify instance.

Config Options:

  • baseURL (String) - Base URL for all requests
  • timeout (Number) - Default timeout in milliseconds (default: 1000)
  • headers (Object) - Default headers

HTTP Methods

All methods return a Promise that resolves to the fetch Response object.

  • instance.get(endpoint, config) - GET request
  • instance.post(endpoint, config) - POST request
  • instance.put(endpoint, config) - PUT request
  • instance.patch(endpoint, config) - PATCH request
  • instance.delete(endpoint, config) - DELETE request

Interceptors

  • instance.addRequestInterceptor(successHandler, errorHandler) - Intercept requests
  • instance.addResponseInterceptor(successHandler, errorHandler) - Intercept responses

Quick Reference

// Create
const api = fetchify.create({ baseURL: '...', timeout: 5000 });

// Requests
await api.get('/path');
await api.post('/path', { body: JSON.stringify(data) });
await api.put('/path', { body: JSON.stringify(data) });
await api.patch('/path', { body: JSON.stringify(data) });
await api.delete('/path');

// Interceptors
api.addRequestInterceptor((config) => { return config; });
api.addResponseInterceptor((response) => { return response; });

License

MIT License - Free to use and modify

Author

Rutansh Chawla


Version: 1.0.5