Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/BetterTyped/hyper-fetch
⚡ Fetching and realtime data exchange framework.
https://github.com/BetterTyped/hyper-fetch
ajax builder cache data-exchange fetch firebase graphql javascript nextjs offline persistence query react realtime sockets sse swr typescript websockets xhr
Last synced: about 2 months ago
JSON representation
⚡ Fetching and realtime data exchange framework.
- Host: GitHub
- URL: https://github.com/BetterTyped/hyper-fetch
- Owner: BetterTyped
- License: apache-2.0
- Created: 2021-10-22T09:02:45.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T09:46:07.000Z (3 months ago)
- Last Synced: 2024-10-29T14:56:12.351Z (3 months ago)
- Topics: ajax, builder, cache, data-exchange, fetch, firebase, graphql, javascript, nextjs, offline, persistence, query, react, realtime, sockets, sse, swr, typescript, websockets, xhr
- Language: TypeScript
- Homepage: https://hyperfetch.bettertyped.com/
- Size: 13.8 MB
- Stars: 1,033
- Watchers: 4
- Forks: 28
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: Contributing.md
- Funding: .github/FUNDING.yml
- License: License.md
- Code of conduct: Code_of_Conduct.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-typesafe - BetterTyped/hyper-fetch - Hyper Fetch is a data-exchange framework focusing on type-safe design and ease of use. (**1. Libraries** / APIs)
README
Framework for fetching and realtime data exchange.
**[Documentation](https://hyperfetch.bettertyped.com/) |
[Quick Start](https://hyperfetch.bettertyped.com/docs/documentation/getting-started/quick-start) |
[Guides](https://hyperfetch.bettertyped.com/docs/guides/Basic/Setup)**
**`Hyper Fetch`** is unique fetching and realtime data-exchange framework meticulously crafted to **prioritize
simplicity and efficiency**. Its **typesafe design** and **user-friendly interface** ensure a seamless integration
experience, whether you're working on the browser or the server. Next-generation features streamlines architecture
creation, grants access to the request lifecycle, and empowers rapid development of new components and functionalities,
all while facilitating **real-time data exchange**.---
## Key Features
🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/basic/setup)
🎯 **Easy cancellation** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Cancellation)
✨ **Deduplicate similar requests** -
[Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/deduplication/)🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/queueing)
💎 **Response Caching** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/core/cache)
🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/offline)
📡 **Built-in fetcher** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/core/adapter)
🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/basic/authentication)
🔁 **Smart Retries** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/basic/retries/)
## Help me keep working on this project ❤️
- [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
## Installation
The easiest way to get the latest version of Hyper Fetch is to install it via yarn or npm.
#### [Core](https://hyperfetch.bettertyped.com/docs/documentation/core/overview)
```bash
npm install --save @hyper-fetch/core
or
yarn add @hyper-fetch/core
```#### [Sockets](https://hyperfetch.bettertyped.com/docs/documentation/sockets/overview)
```bash
npm install --save @hyper-fetch/sockets
or
yarn add @hyper-fetch/sockets
```#### [React](https://hyperfetch.bettertyped.com/docs/documentation/react/overview)
```bash
npm install --save @hyper-fetch/core @hyper-fetch/react
or
yarn add @hyper-fetch/core @hyper-fetch/react
```## Packages
Package
Stats
Hyper Fetch
Sockets
React
Firebase
Firebase Admin
GraphQL
Axios
Codegen Openapi
## Examples
#### Simple Setup
```tsx
import { Client } from "@hyper-fetch/core";// Setup our connection to the server
export const client = new Client({ url: "http://localhost:3000" });// Create reusable requests for later use
export const postData = client.createRequest()({
method: "POST",
endpoint: "/data/:accountId",
});export const getData = client.createRequest()({
method: "GET",
endpoint: "/user",
});
```#### Fetching
Executing previously prepared requests is very simple. We can do this using the send method.
```ts
const { data, error, status } = await getData.send();
```#### Mutation request
We can attach the data to the request with methods before sending it to the server. This is helpful for building our
request and attaching data to it which can be helpful when we need to create it in a few steps from data obtained during
some process.```ts
// Set the information to request (methods return request clone - NOT mutating the source)
const request = postData
.setParams({ accountId: 104 }) // Set Params
.setQueryParams({ paramOne: "test", paramTwo: "test2" })
.setData({ name: "My new entity", description: "Some description" }) // Add payload data
.send();
```We can also pass them directly to the send method, which will add them to the request at once.
```ts
// OR pass dynamic data directly to '.send' method
const { data, error, status } = await postData.send({
params: { accountId: 104 },
data: { name: "My new entity", description: "Some description" },
queryParams: { paramOne: "test", paramTwo: "test2" },
});
```### React
#### Fetch with lifecycle
Show me example
```tsx
import { useFetch } from "@hyper-fetch/react";// Lifecycle fetching
const { data, error, loading, onSuccess, onError } = useFetch(getData);onSuccess((data) => {
console.log(data);
});onError((error) => {
console.log(error);
});
```#### Manually trigger requests
Show me example
```tsx
import { useSubmit } from "@hyper-fetch/react";const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(request);
onSuccess((data) => {
console.log(data);
});onError((error) => {
console.log(error);
});return submit()}>Trigger request!;
```#### Pass dynamic data to submit method
Show me example
```tsx
import { useSubmit } from "@hyper-fetch/react";const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(request);
onSuccess((data) => {
console.log(data);
});onError((error) => {
console.log(error);
});return (
submit({
params: { accountId: 104 },
data: { name: "My new entity", description: "Some description" },
queryParams: { paramOne: "test", paramTwo: "test2" },
})
}
>
Trigger request!
);
```#### Use submit promise response
Show me example
```tsx
import { useSubmit } from "@hyper-fetch/react";// Manual triggering
const { submit, data, error, submitting, onSubmitSuccess, onSubmitError } = useSubmit(request);onSuccess((data) => {
console.log(data);
});onError((error) => {
console.log(error);
});const handleSubmit = (values: ValuesType, { setSubmitting }: FormikHelpers) => {
const { data, error, status } = await submit(); // Submit method returns data!
setSubmitting(false);
if (data) {
notification.success("Done!", data);
} else {
notification.success("Error!", error);
}
};return ...;
```# [Find out more examples](https://hyperfetch.bettertyped.com/docs/guides/basic/setup)
## 💖 Our sponsors