You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-12Lines changed: 39 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,9 @@
11
11
12
12
# @gkoos/ffetch
13
13
14
-
**A production-ready TypeScript-first drop-in replacement for native fetch.**
14
+
**A production-ready TypeScript-first drop-in replacement for native fetch, or any fetch-compatible implementation.**
15
+
16
+
ffetch can wrap any fetch-compatible implementation (native fetch, node-fetch, undici, or framework-provided fetch), making it flexible for SSR, edge, and custom environments.
For older environments, see the [compatibility guide](./docs/compatibility.md).
106
129
130
+
**Custom fetch support:**
131
+
You can pass any fetch-compatible implementation (native fetch, node-fetch, undici, SvelteKit, Next.js, Nuxt, or a polyfill) via the `fetchHandler` option. This makes ffetch fully compatible with SSR, edge, metaframework environments, custom backends, and test runners.
132
+
107
133
## CDN Usage
108
134
109
135
```html
@@ -117,17 +143,18 @@ For older environments, see the [compatibility guide](./docs/compatibility.md).
ffetch can wrap any fetch-compatible implementation using the `fetchHandler` option. This includes native fetch, node-fetch, undici, or framework-provided fetch (SvelteKit, Next.js, Nuxt, etc.), as well as polyfills and test runners. All advanced features (timeouts, retries, circuit breaker, hooks, pending requests) work identically regardless of the underlying fetch implementation, making ffetch highly flexible for SSR, edge, and custom environments.
40
+
37
41
## Pending Requests Monitoring
38
42
39
-
> **Technical Note:**
40
-
> Every `PendingRequest` always has a `controller` property, even if you did not supply an AbortController. This allows you to abort any pending request programmatically, regardless of how it was created.
43
+
Pending requests and abort logic work identically whether you use the default global fetch or a custom fetch implementation via `fetchHandler`. All requests are tracked, and you can abort them programmatically using the controller in each `PendingRequest`.
44
+
45
+
Every `PendingRequest` always has a `controller` property, even if you did not supply an AbortController. This allows you to abort any pending request programmatically, regardless of how it was created.
41
46
42
-
> When multiple signals (user, timeout, transformRequest) are combined and `AbortSignal.any` is not available, ffetch creates a new internal `AbortController` to manage aborts. This controller is always available in `PendingRequest.controller`.
47
+
When multiple signals (user, timeout, transformRequest) are combined and `AbortSignal.any` is not available, ffetch creates a new internal `AbortController` to manage aborts. This controller is always available in `PendingRequest.controller`.
43
48
44
-
> You can always abort a pending request using `pendingRequest.controller.abort()`, even if you did not provide a controller or signal. This works for all requests tracked in `pendingRequests`.
49
+
You can always abort a pending request using `pendingRequest.controller.abort()`, even if you did not provide a controller or signal. This works for all requests tracked in `pendingRequests`.
45
50
46
51
You can access and monitor all active requests through the `pendingRequests` property on the client instance:
Copy file name to clipboardExpand all lines: docs/api.md
+37-9Lines changed: 37 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## createClient(options?)
4
4
5
-
Creates a new HTTP client instance with the specified configuration.
5
+
Creates a new HTTP client instance with the specified configuration. You can use ffetch as a drop-in replacement for native fetch, or wrap any fetch-compatible implementation (e.g., node-fetch, undici, SvelteKit/Next.js/Nuxt-provided fetch) for SSR, edge, and custom environments.
For SvelteKit, Next.js, and Nuxt, you must pass the exact fetch instance provided by the framework in your handler or context. This is not the global fetch, and the parameter name may vary (often `fetch`, but check your framework docs).
359
+
360
+
**SvelteKit example:**
361
+
362
+
```typescript
363
+
// In load functions, actions, or endpoints, use the provided fetch
> Always use the fetch instance provided by the framework in your handler/context, not the global fetch. The parameter name may vary, but it is always context-specific.
ffetch can now be used as a drop-in wrapper for custom fetch implementations. This makes migration easier for SSR/metaframeworks (SvelteKit, Next.js, Nuxt, etc.) and for environments where you need to provide your own fetch (e.g., node-fetch, undici, framework-provided fetch).
49
+
50
+
Simply pass your custom fetch implementation using the `fetchHandler` option:
0 commit comments