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

api-state-factory

v1.0.0

Published

A lightweight, type-safe frontend integration library for REST APIs with Redux

Readme

API State Factory 🚀

The fastest way to build type-safe, production-ready API layers for React & Redux.

API State Factory is a lightweight, zero-boilerplate utility that transforms your API definitions into fully-managed Redux slices, high-performance React hooks, and type-safe direct-call methods.

MIT License TypeScript


🔥 Why API State Factory?

Most state management libraries require you to write hundreds of lines of "glue code" for every endpoint. API State Factory reduces this to a single configuration.

  • Zero Boilerplate: Define an endpoint with a string; get a slice, thunk, and hook instantly.
  • Enterprise Caching: Built-in parameterized caching (multi-slot storage) so navigating between different items is instant.
  • Extreme Type Safety: Full end-to-end IntelliSense for paths, parameters, bodies, and responses.
  • Ultra Lightweight: A fraction of the size of traditional data-fetching libraries.
  • Modern UX Ready: Dual-boolean states (loading vs isRefreshing) for shimmer-free updates.

🎯 Best Use Cases

API State Factory is an industrial-grade tool designed for:

  • HRMS & ERP Systems: Where complex dependencies and data consistency are critical.
  • Admin Dashboards & CRMs: Where rapid development of hundreds of CRUD endpoints is required.
  • Fintech & Banking: Where strict type safety and global error handling are non-negotiable.
  • Large Enterprise Apps: Where reducing Redux boilerplate is a structural necessity.

🚫 When to Consider Alternatives

While powerful, it is not suited for:

  • Real-time Apps: High-frequency trading or gaming (use WebSockets/Socket.io).
  • GraphQL-Dedicated Projects: Use Apollo Client or Urql if you rely on GraphQL schemas.
  • Collaborative Editors: Google Docs-style syncing (requires CRDTs/OT).
  • Hyper-Lightweight Pages: If you don't already use Redux, this is not a standalone fetcher.

📦 Installation

npm install api-state-factory

🚀 Quick Start

1. Define your API

Create a clean, centralized definition of your service.

import { defineApi, endpoint } from 'api-state-factory';

export const expenseApi = defineApi({
  name: 'expenses',
  baseUrl: 'https://api.example.com/v1',
  endpoints: {
    // Shorthand for simple GET requests
    getExpenses: 'GET /expenses',
    
    // Advanced definition with full configuration
    deleteExpense: endpoint.delete('/expenses/:id', {
      invalidates: ['getExpenses'], // Automatically re-fetches the list on success
      retry: 2                      // Auto-retry twice on network glitch
    }),
    
    // Infinite list support
    getFeed: endpoint.get('/feed', { merge: true }) 
  }
});

2. Setup Store (The 1-Line Way)

No more complex combineReducers or middleware setup.

import { createApiStore } from 'api-state-factory';
import { expenseApi } from './api';

export const store = createApiStore({
  apis: [expenseApi]
});

3. Use in Components

Hooks are reactive by default—they fetch on mount and re-fetch when params change.

function ExpenseList() {
  const { data, loading, isRefreshing } = expenseApi.useGetExpenses();

  if (loading) return <Shimmer />;

  return (
    <div>
      {isRefreshing && <span>Updating...</span>}
      {data.map(exp => <Item key={exp.id} {...exp} />)}
    </div>
  );
}

🛠️ Advanced Features

Parameterized Caching (Multi-Slot Storage)

Unlike basic libraries that store one result per endpoint, API State Factory partitions data by parameters. If you visit useGetUser(1) and then useGetUser(2), the data for User 1 is preserved. Navigation back to User 1 is instant.

List Merging (Infinite Scroll)

Stop writing [...oldData, ...newData] logic. Set merge: true and the library handles the array appending for you.

Global Interceptors & Interceptors

Easily handle Auth tokens and global errors.

import { setGlobalConfig } from 'api-state-factory';

setGlobalConfig({
  headers: () => ({
    Authorization: `Bearer ${localStorage.getItem('token')}`
  }),
  onError: (error) => {
    if (error.status === 401) logout();
  }
});

Direct Thunk Access

Need to trigger an API call from outside React (e.g., inside another thunk)?

await store.dispatch(expenseApi.thunks.getExpenses());

⚡ Comparison

| Feature | Legacy Setup | API State Factory | | :--- | :--- | :--- | | Setup Time | Hours/Days | Minutes | | Boilerplate | High (Slices, Thunks, Reducers) | Zero | | Type Safety | Manual Interfaces | Automatic Inference | | UX | Full-screen spinners | Smooth Refreshing | | Caching | Manual Management | Automatic Multi-Slot |


📜 License

MIT © Prajwal D R