Quick Start · Documentation · Guides · Discord
npm install @hyper-fetch/coreimport { createClient } from "@hyper-fetch/core";
// Create a client. It is the single entry point for all your API calls
const client = createClient({ url: "https://api.example.com" });
// Define a typed request. The response shape is inferred everywhere from here
const getUsers = client.createRequest<{ response: { id: number; name: string }[] }>()({
endpoint: "/users",
method: "GET",
});
// Send it. data, error and status are fully typed
const { data, error, status } = await getUsers.send();npx @hyper-fetch/cli generate --url https://api.example.com/openapi.jsonimport { createSdk } from "./api-openapi.sdk";
const sdk = createSdk(client);
// Every endpoint from your schema is available as a typed request
const { data } = await sdk.users.$get.send();A typical app glues together a fetch wrapper, a query cache, a socket client, a codegen step and a mocking library. Each one brings its own types, its own retry logic and its own bugs. Hyper Fetch is one typed layer for all of it.
| You usually combine | With Hyper Fetch you get |
|---|---|
fetch or an Axios wrapper |
createClient() with swappable adapters |
| TanStack Query or SWR | Cache, deduplication, retries and React hooks built in |
| A socket client | Typed Socket listeners and emitters |
| OpenAPI codegen | npx @hyper-fetch/cli generate |
| A tRPC, oRPC, Hono or Eden client | createSdk typed from your router |
| MSW and hand-written mocks | setMock() on any request |
- Zero guesswork - Params, payload, query params, response and error are typed on every request. No
any - URL params checked at compile time -
/users/:userIdmakesuserIdrequired. Typos fail the build - Typed from your schema - Point the CLI at OpenAPI and every endpoint becomes a typed request
- Typed from your server - tRPC, oRPC, Hono and Elysia routers type
createSdkdirectly. No codegen step - One request, every layer - The type you declare once flows into
send(), hooks, cache and devtools
- Cache with stale time - Fresh data comes from cache. Stale data revalidates in the background
- Persisted cache - Plug in
lazyStorageand the cache survives reloads - No duplicate calls - Identical requests in flight share one response
- Optimistic updates - Show the result now.
optimistic()rolls it back if the request fails - Pagination and streams -
useInfiniteFetchfor endless lists,useStreamfor streamed responses
- Collections -
@hyper-fetch/dbkeeps each row once, filled by requests and sockets alike - Live queries -
where,orderByandjoingo to the server when they can and run in memory otherwise - Transactions - Group writes with
db.transaction(). They show at once, queue offline and roll back on failure
- Retries - Set attempts and delay per request with
setRetry()andsetRetryTime() - Offline queue - Requests sent offline wait and replay when the connection returns
- Cancel anything - Abort one request or a whole group by its abort key
- Progress - Upload and download progress events with time estimates
- WebSockets and SSE, one API - Typed listeners and emitters for both protocols
- Reconnects on its own - Configurable reconnect attempts and timing
- No render floods - Batch messages or keep only the latest one before they reach React
- Devtools - HyperFlow shows every request, the cache and the queue live
- Mocking -
setMock()on any request returns your data and status with no network call - ESLint plugin - Catches empty and misspelled generic types on requests and clients
- Works everywhere - React, Next.js, Remix, Astro, Node.js and Bun. SSR hydration included
REST |
OpenAPI |
GraphQL |
tRPC |
oRPC |
Hono |
Elysia |
Firebase |
Firebase Admin |
Axios |
Sockets & SSE |
React |
Hyper Fetch is the data layer inside Hype Stack, the full-stack template I build alongside it.
| Package | Version | Downloads | Size |
|---|---|---|---|
@hyper-fetch/coreThe client, requests, cache, queues, retries and offline support |
|||
@hyper-fetch/reactuseFetch, useSubmit, useListener and the rest of the React hooks |
|||
@hyper-fetch/socketsTyped WebSocket and Server-Sent Events listeners and emitters |
|||
@hyper-fetch/dbCollections and live queries over every request and socket |
|||
@hyper-fetch/cliGenerates a typed SDK from an OpenAPI schema |
|||
@hyper-fetch/graphqlGraphQL queries and mutations with gql documents |
|||
@hyper-fetch/trpctRPC procedures as typed requests, inferred from your router |
|||
@hyper-fetch/orpcoRPC procedures as typed requests, inferred from your router |
|||
@hyper-fetch/honoA typed SDK from your Hono app type. Types only, no server code |
|||
@hyper-fetch/elysiaA typed SDK from your Elysia app type. Types only, no server code |
|||
@hyper-fetch/firebaseFirestore and Realtime Database from the browser |
|||
@hyper-fetch/firebase-adminFirestore and Realtime Database from the server |
|||
@hyper-fetch/axiosRuns every request through Axios |
|||
@hyper-fetch/plugin-devtoolsConnects your app to the HyperFlow devtools |
|||
eslint-plugin-hyper-fetchLint rules for request and client generic types |
|||
oxlint-plugin-hyper-fetchThe same rules on Oxlint, the Rust linter |
// Every value you get back is typed
const { data, error, status } = await getUsers.send();// Params go in the URL and the payload goes in the body. Both are typed
const { data, error, status } = await createUser.send({
params: { teamId: 1 },
payload: { name: "Jane", email: "jane@example.com" },
});import { useFetch } from "@hyper-fetch/react";
const UserList = () => {
// useFetch triggers the request on mount and returns typed state
const { data, loading, error } = useFetch(getUsers);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error loading users</p>;
return (
<ul>
{data?.map((u) => (
<li key={u.id}>{u.name}</li>
))}
</ul>
);
};