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

fluid-fetch

v0.0.3

Published

Fetching package tiny enough for client apps. Zero dependencies. Fluid (chainable) API.

Readme

fluid-fetch β

A lightweight and flexible HTTP client for JavaScript and TypeScript applications, providing a fluid/chainable API for making HTTP requests. FluidFetch is designed to be tiny yet powerful, making it perfect for client-side applications where bundle size matters.

Features

  • 🔄 Chainable API - Build requests with a fluent interface
  • 🚀 Promise-based - Works with async/await and Promise methods
  • 💾 Caching - Built-in request caching with configurable TTL
  • ⏱️ Timeouts - Automatic request timeout handling
  • 🔌 Middleware support - Intercept and modify requests and responses
  • 🔄 Request cancellation - Cancel ongoing requests
  • 📦 TypeScript support - Full TypeScript definitions included

Installation

npm i fluid-fetch

Basic Usage

import FluidFetch from 'fluid-fetch';

const api = new FluidFetch();

// Simple GET request
const response = await api.get('https://api.example.com/users');
const data = await response.json();

// POST request with data
const createUser = await api.post('https://api.example.com/users', {
  name: 'Dwight Schrute',
  email: '[email protected]'
});

Chainable API

FluidFetch provides a fluent interface for configuring requests:

const response = await api.get('https://api.example.com/posts')
  .headers({
    'Authorization': 'Bearer token123',
    'Accept': 'application/json'
  })
  .params({
    page: 1,
    limit: 20,
    sort: 'newest'
  })
  .cache(true)
  .timeout(5000);

const data = await response.json();

Request Methods

FluidFetch supports all common HTTP methods:

// GET request
api.get(url, config);

// POST request with data
api.post(url, data, config);

// PUT request with data
api.put(url, data, config);

// DELETE request
api.delete(url, config);

Request Configuration

You can configure requests in two ways:

  1. Pass a config object when creating the request
  2. Use the chainable methods
// Method 1: Config object
api.get('https://api.example.com/users', {
  headers: {
    'Authorization': 'Bearer token123'
  },
  params: {
    active: true
  },
  cache: true,
  timeout: 5000
});

// Method 2: Chainable methods (preferred)
api.get('https://api.example.com/users')
  .headers({
    'Authorization': 'Bearer token123'
  })
  .params({
    active: true
  })
  .cache(true)
  .timeout(5000);

Caching

FluidFetch includes built-in request caching:

// Enable caching with default TTL (1 hour)
api.get('https://api.example.com/users').cache(true);

// Specify cache TTL in milliseconds (e.g., 5 minutes)
api.get('https://api.example.com/users').cache(5 * 60 * 1000);

Timeouts

Set request timeouts to avoid hanging requests:

// Timeout after 5 seconds (5000ms)
api.get('https://api.example.com/users').timeout(5000);

Request Cancellation

Cancel in-flight requests:

const request = api.get('https://api.example.com/large-data');

// Later in your code
request.cancel();

Middleware Support

FluidFetch provides powerful middleware support for both requests and responses:

// Request middleware
api.middlewares.request.use((request) => {
  // Add authorization token to all requests
  request.headers['Authorization'] = 'Bearer ' + getToken();
  return request;
});

// Response middleware
api.middlewares.response.use((response) => {
  // Log all responses
  console.log('Response received', response.status);
  return response;
});

Error Handling in Middleware

api.middlewares.request.use(
  // Success handler
  (request) => {
    // Modify request
    return request;
  },
  // Error handler
  (error) => {
    console.error('Request middleware error:', error);
    throw error; // Re-throw or handle as needed
  }
);

TypeScript Support

FluidFetch includes full TypeScript definitions and supports generic type parameters:

interface User {
  id: number;
  name: string;
  email: string;
}

// Specify the expected response type
const response = await api.get<User>('https://api.example.com/users/1');
const user = await response.json();
// user is now of type User