{"id":26410452,"url":"https://github.com/hoangsonww/fastfetch-api-fetch-enhancer","last_synced_at":"2026-05-11T02:47:49.188Z","repository":{"id":282764073,"uuid":"949578279","full_name":"hoangsonww/FastFetch-API-Fetch-Enhancer","owner":"hoangsonww","description":"⚡ FastFetch – An NPM package for a smarter fetch() wrapper with auto-retry, deduplication, and minimal boilerplate for efficient API requests. Stop redundant calls and handle failures seamlessly with built-in retry logic!","archived":false,"fork":false,"pushed_at":"2025-03-16T19:33:54.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T20:30:23.446Z","etag":null,"topics":["api","api-fetch","api-rest","auto-retry","axios","cache","deduplication","exponential-backoff","fast-fetch","fetch","fetch-api","fetch-data","frontend","ghost-cache","node-package-manager","nodejs","npm","npm-package","retry","smart-api"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@hoangsonw/fast-fetch","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hoangsonww.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-16T19:02:22.000Z","updated_at":"2025-03-16T19:33:57.000Z","dependencies_parsed_at":"2025-03-16T20:40:32.915Z","dependency_job_id":null,"html_url":"https://github.com/hoangsonww/FastFetch-API-Fetch-Enhancer","commit_stats":null,"previous_names":["hoangsonww/fastfetch-api-fetch-enhancer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FFastFetch-API-Fetch-Enhancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FFastFetch-API-Fetch-Enhancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FFastFetch-API-Fetch-Enhancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoangsonww%2FFastFetch-API-Fetch-Enhancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoangsonww","download_url":"https://codeload.github.com/hoangsonww/FastFetch-API-Fetch-Enhancer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244102849,"owners_count":20398386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-fetch","api-rest","auto-retry","axios","cache","deduplication","exponential-backoff","fast-fetch","fetch","fetch-api","fetch-data","frontend","ghost-cache","node-package-manager","nodejs","npm","npm-package","retry","smart-api"],"created_at":"2025-03-17T20:17:54.180Z","updated_at":"2026-05-11T02:47:49.145Z","avatar_url":"https://github.com/hoangsonww.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastFetch - Improve API Fetching with Auto-Retry and Deduplication\n\n[![NPM version](https://img.shields.io/npm/v/@hoangsonw/fast-fetch.svg?style=flat\u0026logo=npm)](https://www.npmjs.com/package/@hoangsonw/fast-fetch)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat\u0026logo=opensource)](LICENSE)\n[![Node.js](https://img.shields.io/badge/Node-%3E%3D14-brightgreen.svg?style=flat\u0026logo=node.js)](https://nodejs.org/)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.0%2B-blue.svg?style=flat\u0026logo=typescript)](https://www.typescriptlang.org/)\n[![Axios](https://img.shields.io/badge/Axios-1.3.0-blue.svg?style=flat\u0026logo=axios)](https://github.com/axios/axios)\n\n**FastFetch** is a smarter `fetch()` wrapper that adds **auto-retry** and **request deduplication** to standard HTTP requests, reducing boilerplate and increasing resilience. It is designed to work seamlessly in both Node.js and browser environments using modern ES modules.\n\nCurrently live on NPM at [https://www.npmjs.com/package/@hoangsonw/fast-fetch](https://www.npmjs.com/package/@hoangsonw/fast-fetch). This package is a work in progress, and we welcome contributions and feedback!\n\n\u003e Note: Currently, **FastFetch** does not support caching. For caching, consider using [GhostCache](https://www.npmjs.com/package/ghost-cache) in conjunction with FastFetch :)\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Usage with Fetch](#basic-usage-with-fetch)\n  - [Using FastFetch with Auto-Retry \u0026 Deduplication](#using-fastfetch-with-auto-retry--deduplication)\n  - [Using FastFetch with Axios](#using-fastfetch-with-axios)\n- [API Reference](#api-reference)\n- [Configuration Options](#configuration-options)\n- [Advanced Examples](#advanced-examples)\n- [Testing](#testing)\n- [Demo Script](#demo-script)\n- [License](#license)\n- [Contributing](#contributing)\n\n## Features\n\n- **Auto-Retry:** Automatically retries failed HTTP requests with configurable delay and retry count.\n- **Request Deduplication:** Merges multiple identical in-flight requests into a single network call.\n- **Minimal Boilerplate:** Wraps the native `fetch()` function with enhanced functionality.\n- **TypeScript Support:** Fully written in TypeScript with complete type definitions.\n- **ESM Compatible:** Compiled using NodeNext module resolution for seamless ESM integration.\n\n## Installation\n\n### Prerequisites\n\n- Node.js v14 or higher\n- npm v6 or higher\n\n### Installing via NPM\n\n```bash\nnpm install @hoangsonw/fast-fetch\n```\n\n### Installing via Yarn\n\n```bash\nyarn add @hoangsonw/fast-fetch\n```\n\n## Usage\n\nFastFetch can be used as a drop-in replacement for the native `fetch()` function with additional options.\n\n### Basic Usage with Fetch\n\nBelow is a simple example that uses FastFetch to make an API call and print the results:\n\n```js\nimport { fastFetch } from \"@hoangsonw/fast-fetch\";\n\nfastFetch(\"https://pokeapi.co/api/v2/pokemon/ditto\")\n  .then((res) =\u003e res.json())\n  .then((data) =\u003e {\n    console.log(\"Fetched data:\", data);\n  })\n  .catch((err) =\u003e console.error(\"Fetch error:\", err));\n```\n\n### Using FastFetch with Auto-Retry \u0026 Deduplication\n\nFastFetch supports auto-retry and deduplication through additional options. For example, you can automatically retry up to 2 times with a delay of 2000ms between attempts, and deduplicate in-flight requests:\n\n```js\nimport { fastFetch } from \"@hoangsonw/fast-fetch\";\n\nfastFetch(\"https://pokeapi.co/api/v2/pokemon/ditto\", {\n  retries: 2,\n  retryDelay: 2000,\n  deduplicate: true,\n  shouldRetry: (errorOrResponse, attempt) =\u003e {\n    console.log(`Retry attempt #${attempt}`);\n    // If response exists and status is 5xx, retry\n    if (errorOrResponse instanceof Response) {\n      return errorOrResponse.status \u003e= 500;\n    }\n    // For network errors or other errors, retry\n    return true;\n  },\n})\n  .then((res) =\u003e res.json())\n  .then((data) =\u003e console.log(\"FastFetch data:\", data))\n  .catch((err) =\u003e console.error(\"FastFetch error:\", err));\n```\n\n### Using FastFetch with Axios\n\nFastFetch can deduplicate in-flight requests even when used alongside Axios by registering an Axios instance. This means if multiple identical requests are made concurrently via Axios, only one network call is performed.\n\n```js\nimport axios from \"axios\";\nimport { fastFetch, registerAxios } from \"@hoangsonw/fast-fetch\";\n\n// Create an Axios instance\nconst api = axios.create({ baseURL: \"https://pokeapi.co/api/v2\" });\n\n// Register the Axios instance with FastFetch\nregisterAxios(api);\n\napi\n  .get(\"/pokemon/ditto\")\n  .then((response) =\u003e {\n    console.log(\"Axios fetched data:\", response.data);\n  })\n  .catch((error) =\u003e {\n    console.error(\"Axios error:\", error);\n  });\n```\n\n## API Reference\n\n### `fastFetch(input: RequestInfo, init?: RequestInit \u0026 FastFetchOptions): Promise\u003cResponse\u003e`\n\n- **Parameters:**\n\n  - `input`: URL or Request object.\n  - `init`: An object that extends standard `RequestInit` with additional options:\n    - `retries`: _number_ — Number of retry attempts (default: `0`).\n    - `retryDelay`: _number_ — Delay in milliseconds between retries (default: `1000`).\n    - `deduplicate`: _boolean_ — Whether to deduplicate in-flight requests (default: `true`).\n    - `shouldRetry`: _function_ — A custom function `(errorOrResponse: Response | Error, attempt: number) =\u003e boolean` that determines whether to retry based on error or response status.\n\n- **Returns:**  \n  A `Promise` that resolves to a `Response` object.\n\n### Additional Exports\n\n- **`registerAxios(instance: AxiosInstance): void`**  \n  Registers an Axios instance so that FastFetch can deduplicate in-flight requests for Axios as well.\n\n- **Other functions:**  \n  FastFetch only wraps the native `fetch()` and does not cache responses (use GhostCache if caching is required).\n\n## Configuration Options\n\n- **retries**: Number of times to retry the fetch on failure.\n- **retryDelay**: Delay (in milliseconds) before retrying.\n- **deduplicate**: When set to `true`, identical in-flight requests are deduplicated.\n- **shouldRetry**: Custom function to decide whether to retry a request based on error or response.\n\n## Advanced Examples\n\n### Custom Retry Logic\n\nImplement custom logic to only retry on specific HTTP status codes:\n\n```js\nimport { fastFetch } from \"@hoangsonw/fast-fetch\";\n\nfastFetch(\"https://example.com/api/data\", {\n  retries: 3,\n  retryDelay: 1500,\n  shouldRetry: (errorOrResponse, attempt) =\u003e {\n    if (errorOrResponse instanceof Response) {\n      // Only retry for server errors\n      return errorOrResponse.status \u003e= 500;\n    }\n    return true;\n  },\n})\n  .then((res) =\u003e res.json())\n  .then((data) =\u003e console.log(\"Custom retry data:\", data))\n  .catch((err) =\u003e console.error(\"Error with custom retry:\", err));\n```\n\n### Deduplication in Action\n\nDemonstrate deduplication by firing multiple identical requests simultaneously:\n\n```js\nimport { fastFetch } from \"@hoangsonw/fast-fetch\";\n\nconst url = \"https://pokeapi.co/api/v2/pokemon/ditto\";\n\n// Fire two identical requests concurrently.\nPromise.all([fastFetch(url), fastFetch(url)])\n  .then(async ([res1, res2]) =\u003e {\n    const data1 = await res1.json();\n    const data2 = await res2.json();\n    console.log(\"Deduplication demo, data1:\", data1);\n    console.log(\"Deduplication demo, data2:\", data2);\n  })\n  .catch((err) =\u003e console.error(\"Deduplication error:\", err));\n```\n\n## Testing\n\nFastFetch comes with a Jest test suite. To run tests:\n\n1. **Install dependencies:**\n\n   ```bash\n   npm install\n   ```\n\n2. **Run tests:**\n   ```bash\n   npm test\n   ```\n\nExample test files (found in the `__tests__` directory) demonstrate auto-retry, deduplication, and basic fetch functionality.\n\n## Demo Script\n\nA demo script is included in the `__tests__` directory. To run the demo:\n\n```bash\nnpm run demo\n```\n\nIt will execute a series of fetch requests and demonstrate the auto-retry and deduplication features.\n\n## Contributing\n\nContributions are welcome! Please follow these steps:\n\n1. **Fork the Repository**\n2. **Create a Feature Branch**\n   ```bash\n   git checkout -b feature/my-new-feature\n   ```\n3. **Commit Your Changes**\n4. **Submit a Pull Request**\n\nFor major changes, please open an issue first to discuss your ideas.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Final Remarks\n\nFastFetch is designed to enhance the native `fetch()` experience by adding auto-retry and deduplication features, making your API requests more robust and efficient without caching (use GhostCache for caching). Enjoy building resilient applications!\n\nHappy fetching! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoangsonww%2Ffastfetch-api-fetch-enhancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoangsonww%2Ffastfetch-api-fetch-enhancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoangsonww%2Ffastfetch-api-fetch-enhancer/lists"}