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
fetchff is an open-source project aimed at simplifying and enhancing HTTP requests in JavaScript applications. As an open-source project, it thrives on community support and contributions. Your support helps ensure that fetchff remains sustainable and continues to grow. If you find fetchff useful and would like to support its ongoing development, here are a few ways you can help:
4
+
5
+
## Ways to Support
6
+
7
+
### 1. **GitHub Sponsorship**
8
+
9
+
You can sponsor the fetchff project directly on GitHub. Your contributions help cover development costs and allow us to invest more time into improving the library.
10
+
11
+
<i>[This option is currently unavailable]</i>
12
+
13
+
<!-- [Become a Sponsor on GitHub](https://github.com/sponsors) -->
14
+
15
+
### 2. **Patreon**
16
+
17
+
Consider supporting fetchff through Patreon. Your monthly contributions will provide us with the resources needed to maintain and enhance the project.
18
+
19
+
[Support Us on Patreon](https://www.patreon.com/mattccc)
20
+
21
+
### 3. **Contributions**
22
+
23
+
If financial support isn't feasible for you at the moment, there are other ways to contribute:
24
+
25
+
-**Report Issues**: Help us identify bugs or areas for improvement by reporting issues on GitHub.
26
+
-**Feature Requests**: Share your ideas for new features or enhancements.
27
+
-**Documentation**: Contribute to our documentation to help others understand and use fetchff more effectively.
28
+
-**Spread the Word**: Share fetchff with your colleagues and on social media. The more users we have, the more vibrant our community becomes!
29
+
30
+
## Thank You!
31
+
32
+
Your support, whether financial or in the form of contributions, helps ensure the longevity and success of fetchff. Together, we can make this project sustainable and even better!
33
+
34
+
---
35
+
36
+
For more information on how to contribute to fetchff, please refer to our [CONTRIBUTING.md](./CONTRIBUTING.md) file.
<summary><spanstyle="cursor:pointer">Click to expand</span></summary>
176
176
<br>
177
177
178
-
All the Request Settings can be used directly in the function or in the `endpoints` property (on per-endpoint basis). There are also two extra global settings for `createApiFetcher()`:
178
+
All the Request Settings can be directly used in the function as global settings for all endpoints. They can be also used within the `endpoints` property (on per-endpoint basis). The exposed `endpoints` property is as follows:
| endpoints |`object`|| List of your endpoints. Each endpoint accepts all the settings below. They can be set globally, per-endpoint or per-request. |
183
-
| fetcher |`FetcherInstance`|| A custom adapter (an instance / object) that exposes `create()` function so to create instance of API Fetcher. The `create()` should return `request()` function that would be used when making the requests. The native `fetch()` is used if the fetcher is not provided. |
180
+
-**`endpoints`**:
181
+
Type: `EndpointsConfig<EndpointsMethods>`
182
+
List of your endpoints. Each endpoint is an object that accepts all the Request Settings (see the Basic Settings below). The endpoints are required to be specified.
184
183
185
184
#### How It Works
186
185
@@ -206,7 +205,7 @@ import { createApiFetcher } from 'fetchff';
206
205
const api =createApiFetcher({
207
206
apiUrl: 'https://example.com/api',
208
207
endpoints: {
209
-
updateUserData: {
208
+
updateUser: {
210
209
url: '/update-user/:id',
211
210
method: 'POST',
212
211
},
@@ -215,7 +214,7 @@ const api = createApiFetcher({
@@ -279,7 +278,8 @@ You can also use all native `fetch()` settings.
279
278
| withCredentials |`boolean`|`false`| Indicates whether credentials (such as cookies) should be included with the request. |
280
279
| timeout |`number`|`30000`| You can set a request timeout for all requests or particular in milliseconds. |
281
280
| dedupeTime |`number`|`1000`| Time window, in milliseconds, during which identical requests are deduplicated (treated as single request). |
282
-
| logger |`object`|`null`| You can additionally specify logger object with your custom logger to automatically log the errors to the console. It should contain at least `error` and `warn` functions. |
281
+
| logger |`Logger`|`null`| You can additionally specify logger object with your custom logger to automatically log the errors to the console. It should contain at least `error` and `warn` functions. |
282
+
| fetcher |`FetcherInstance`|| A custom adapter (an instance / object) that exposes `create()` function so to create instance of API Fetcher. The `create()` should return `request()` function that would be used when making the requests. The native `fetch()` is used if the fetcher is not provided. |
283
283
284
284
## 🏷️ Headers
285
285
@@ -291,25 +291,6 @@ You can also use all native `fetch()` settings.
291
291
292
292
**Note:** Header keys are case-sensitive when specified in request objects. Ensure that the keys are provided in the correct case to avoid issues with header handling.
293
293
294
-
### How to Set Per-Request Headers
295
-
296
-
To set headers for a specific request, include the `headers` option in the request configuration. This option accepts an `object` where the keys are the header names and the values are the corresponding header values.
297
-
298
-
### Default Headers
299
-
300
-
The `fetchff` plugin automatically injects a set of default headers into every request. These default headers help ensure that requests are consistent and include necessary information for the server to process them correctly.
Indicates the media types that the client is willing to receive from the server. This includes JSON, plain text, and any other types.
309
-
310
-
-**`Accept-Encoding`**: `gzip, deflate, br`
311
-
Specifies the content encoding that the client can understand, including gzip, deflate, and Brotli compression.
312
-
313
294
### Setting Headers Globally
314
295
315
296
You can set default headers that will be included in all requests made with a specific `createApiFetcher` instance. This is useful for setting common headers like authentication tokens or content types.
The `fetchff` plugin automatically injects a set of default headers into every request. These default headers help ensure that requests are consistent and include necessary information for the server to process them correctly.
@@ -1449,7 +1448,7 @@ fetchUserAndCreatePost(1, { title: 'New Post', content: 'This is a new post.' })
1449
1448
<details>
1450
1449
<summary><span style="cursor:pointer">Click to expand</span></summary>
1451
1450
<br>
1452
-
You can implement a `useApi()` hook to handle the data fetching. Since this package has everything included, you don't really need anything more than a simple hook to utilize.<br><br>
1451
+
You can implement a `useFetcher()` hook to handle the data fetching. Since this package has everything included, you don't really need anything more than a simple hook to utilize.<br><br>
1453
1452
1454
1453
Create `api.ts` file:
1455
1454
@@ -1467,10 +1466,10 @@ export const api = createApiFetcher({
0 commit comments