Skip to content

Repository files navigation

Lint Test MIT License


fetchify

A lightweight fetch wrapper with caching, retries, hooks, and timeouts — built for Bun and TypeScript.
Explore the getting-started guide »

Getting Started · API Reference

Table of Contents

About The Project

fetchify is a small wrapper around the native fetch API. It gives you a client with one method per HTTP verb, JSON handling, and typed errors, plus opt-in building blocks for the things you'd otherwise hand-roll around fetch:

  • Caching — pluggable cache adapters (in-memory, Redis, Upstash) that read/write on GET requests, with opt-in invalidation on mutations
  • Retries — exponential backoff with jitter for transient failures (network errors, timeouts, 408/429/5xx)
  • Hooks — a beforeRequest hook for attaching things like auth tokens right before a request goes out
  • Timeouts — per-client or per-request timeouts, composable with a caller-supplied AbortSignal

See DOCS.md for the full API reference.

(back to top)

Built With

(back to top)

Getting Started

Prerequisites

  • Bun installed locally

Installation

Add fetchify as a dependency:

bun install @kamsteegsoftware/fetchify

For a full walkthrough — making your first request, reading responses, and adding a cache adapter — see GETTING-STARTED.md.

(back to top)

Usage

import { createFetchify, FetchifyError } from "@kamsteegsoftware/fetchify";

const client = createFetchify({ baseUrl: "https://api.example.com" });

try {
  const { data, response } = await client.get<User>("/users/1");
  console.log(data);
} catch (error) {
  if (error instanceof FetchifyError) {
    console.error(error.status, error.data);
  } else {
    throw error;
  }
}

For the complete API surface — createFetchify, defineOptions, cache adapters, hooks, retries, and timeouts — see DOCS.md.

(back to top)

Releasing

This project uses Changesets to manage version bumps and changelogs.

  • When making a user-facing change, run bun run changeset and follow the prompts to record what changed and how significant it is (major/minor/patch).
  • Before a release, run bun run version to consume all pending changesets, bump the version in package.json, and update CHANGELOG.md.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

About

A wrapper client for native Fetch in web and react-native

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages