Skip to main content
Version: v10.5.1

Core overview

Define each endpoint once as a typed request, then send it from anywhere. The client behind it caches, dedupes, retries, queues and waits out offline periods. It has no framework dependency.

api.ts
import { createClient } from "@hyper-fetch/core";

// One client per backend
const client = createClient({ url: "https://api.example.com" });

// One request per endpoint, typed once
export const getUser = client.createRequest<{ response: User }>()({
endpoint: "/users/:userId",
});

// `:userId` is a required, typed param. send() never throws.
const { data, error, status } = await getUser.send({ params: { userId: 1 } });

HTTP errors, timeouts, aborts and network failures all resolve with error set. You branch on the result instead of wrapping calls in try/catch.

  1. Request

    Typed endpoint, defined once

  2. Dispatcher

    Dedupes, queues, retries

  3. Adapter

    fetch, Axios, GraphQL, Firebase

  4. Cache

    Stored by cache key

  5. Response

    data, error, status

Every send() takes this path. Each step emits events that hooks and devtools read.

Building blocks​


Requests are templates​

A request is plain, immutable data. Every setter, such as setParams or setQueryParams, returns a new request and leaves the original untouched. So one request serves a component, a server loader, a test and a story, with no custom hook per endpoint. In tests and stories, setMock answers it without a server.


Common tasks​


Next​

Core runs alone in backends and scripts and in shared API packages. In a UI, add a binding on top.