Spoosh

A type-safe API client with a powerful plugin system

import { createSpoosh } from "@spoosh/core";
import { createReactSpoosh } from "@spoosh/react";
import { cachePlugin } from "@spoosh/plugin-cache";
import { deduplicationPlugin } from "@spoosh/plugin-deduplication";
import { invalidationPlugin } from "@spoosh/plugin-invalidation";

const spoosh = createSpoosh<ApiSchema>({
  baseUrl: "/api",
  plugins: [
    cachePlugin({ staleTime: 5000 }),
    deduplicationPlugin(), // Prevent duplicate requests
    invalidationPlugin(), // Auto-refresh queries after mutations
  ],
});

export const { useRead, useWrite } = createReactSpoosh(spoosh);

Why Spoosh?

Type-Safe

Define your API schema once, get full TypeScript autocomplete and type checking everywhere.

Plugin System

Extend functionality with plugins for caching, retry, polling, optimistic updates, and more.

Framework Bindings

useRead, useWrite, and useInfiniteRead hooks for seamless data fetching.

Framework Adapters

First-class support for Hono with automatic type inference from your server routes.

Smart Cache Invalidation

Automatic tag-based cache invalidation after mutations. Your queries stay fresh without manual refetching.

Next.js Ready

Server-side cache revalidation with Next.js App Router and Server Actions.

Simple & Powerful

Fetch data with automatic caching, loading states, and error handling

function UserList() {
  const { data, loading, error, refetch } = useRead(
    (api) => api.users.$get()
  );

  if (loading) return <Spinner />;
  if (error) return <Error message={error.message} />;

  return (
    <ul>
      {data?.map((user) => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
}

Ready to get started?

Install Spoosh and build type-safe API clients in minutes.

npm install @spoosh/core @spoosh/react