Skip to content

Latest commit

 

History

1,749 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hyper Fetch. Fetch anything. Type everything. Cache, retries, dedupe, offline and realtime, built in. Works with OpenAPI, GraphQL, tRPC, oRPC, Hono, Elysia, Node.js, Bun, Firebase, Axios, WebSockets and React.

Quick Start · Documentation · Guides · Discord

GitHub stars npm version Monthly downloads of all packages Bundle size of @hyper-fetch/core TypeScript License Follow on Twitter

🚀 Quick Start

npm install @hyper-fetch/core

Define requests manually

import { 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();

Generate from OpenAPI or backend types

npx @hyper-fetch/cli generate --url https://api.example.com/openapi.json
import { 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();

Platinum sponsor banner

Platinum sponsors

💥 Why HyperFetch?

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

🔮 Types you never write twice

  • Zero guesswork - Params, payload, query params, response and error are typed on every request. No any
  • URL params checked at compile time - /users/:userId makes userId required. 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 createSdk directly. No codegen step
  • One request, every layer - The type you declare once flows into send(), hooks, cache and devtools

💾 Server state handled for you

  • Cache with stale time - Fresh data comes from cache. Stale data revalidates in the background
  • Persisted cache - Plug in lazyStorage and 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 - useInfiniteFetch for endless lists, useStream for streamed responses

🗃️ One store for your data

  • Collections - @hyper-fetch/db keeps each row once, filled by requests and sockets alike
  • Live queries - where, orderBy and join go 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

📴 Built for bad networks

  • Retries - Set attempts and delay per request with setRetry() and setRetryTime()
  • 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

📡 Realtime on the same model

  • 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

🧪 Tooling included

  • 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

🔌 Works with


REST

OpenAPI

GraphQL

tRPC

oRPC

Hono

Elysia

Firebase

Firebase Admin

Axios

Sockets & SSE

React

Try other BetterTyped projects

Hyper Fetch is the data layer inside Hype Stack, the full-stack template I build alongside it.

Build your SaaS on Hype Stack

Gold sponsor banner

Gold sponsors

📦 Packages

Package Version Downloads Size
@hyper-fetch/core
The client, requests, cache, queues, retries and offline support
npm downloads size
@hyper-fetch/react
useFetch, useSubmit, useListener and the rest of the React hooks
npm downloads size
@hyper-fetch/sockets
Typed WebSocket and Server-Sent Events listeners and emitters
npm downloads size
@hyper-fetch/db
Collections and live queries over every request and socket
npm downloads size
@hyper-fetch/cli
Generates a typed SDK from an OpenAPI schema
npm downloads size
@hyper-fetch/graphql
GraphQL queries and mutations with gql documents
npm downloads size
@hyper-fetch/trpc
tRPC procedures as typed requests, inferred from your router
npm downloads size
@hyper-fetch/orpc
oRPC procedures as typed requests, inferred from your router
npm downloads size
@hyper-fetch/hono
A typed SDK from your Hono app type. Types only, no server code
npm downloads size
@hyper-fetch/elysia
A typed SDK from your Elysia app type. Types only, no server code
npm downloads size
@hyper-fetch/firebase
Firestore and Realtime Database from the browser
npm downloads size
@hyper-fetch/firebase-admin
Firestore and Realtime Database from the server
npm downloads size
@hyper-fetch/axios
Runs every request through Axios
npm downloads size
@hyper-fetch/plugin-devtools
Connects your app to the HyperFlow devtools
npm downloads size
eslint-plugin-hyper-fetch
Lint rules for request and client generic types
npm downloads size
oxlint-plugin-hyper-fetch
The same rules on Oxlint, the Rust linter
npm downloads size

Silver sponsor banner

Silver sponsors

Examples

Fetching data

// Every value you get back is typed
const { data, error, status } = await getUsers.send();

Mutation with params and payload

// 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" },
});

React hooks

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>
  );
};

Documentation

Our sponsors

Sponsors

License

Apache-2.0

Releases

Sponsor this project

Used by

Contributors

Languages