1
1
![ Foundatio] ( https://raw.githubusercontent.com/FoundatioFx/Foundatio/master/media/foundatio-dark-bg.svg#gh-dark-mode-only " Foundatio ")
2
2
![ Foundatio] ( https://raw.githubusercontent.com/FoundatioFx/Foundatio/master/media/foundatio.svg#gh-light-mode-only " Foundatio ")
3
3
4
- [ ![ NPM] ( https://img.shields.io/npm/v/%40foundatio %2Ffetchclient )] ( https://www.npmjs.com/package/@foundatio /fetchclient )
5
- [ ![ JSR] ( https://jsr.io/badges/@foundatio /fetchclient )] ( https://jsr.io/@foundatio /fetchclient )
4
+ [ ![ NPM] ( https://img.shields.io/npm/v/%40foundatiofx %2Ffetchclient )] ( https://www.npmjs.com/package/@foundatiofx /fetchclient )
5
+ [ ![ JSR] ( https://jsr.io/badges/@foundatiofx /fetchclient )] ( https://jsr.io/@foundatiofx /fetchclient )
6
6
[ ![ Build status] ( https://github.com/FoundatioFx/Foundatio/workflows/Build/badge.svg )] ( https://github.com/FoundatioFx/Foundatio/actions )
7
7
[ ![ Discord] ( https://img.shields.io/discord/715744504891703319 )] ( https://discord.gg/6HxgFCx )
8
8
@@ -32,19 +32,19 @@ APIs. It provides the following features:
32
32
## Install
33
33
34
34
``` shell
35
- npm install --save @foundatio /fetchclient
35
+ npm install --save @foundatiofx /fetchclient
36
36
```
37
37
38
38
## Docs
39
39
40
- [ API Documentation] ( https://jsr.io/@foundatio /fetchclient/doc )
40
+ [ API Documentation] ( https://jsr.io/@foundatiofx /fetchclient/doc )
41
41
42
42
## Usage
43
43
44
44
### Typed Response
45
45
46
46
``` ts
47
- import { FetchClient } from " @foundatio /fetchclient" ;
47
+ import { FetchClient } from " @foundatiofx /fetchclient" ;
48
48
49
49
type Products = {
50
50
products: Array <{ id: number ; name: string }>;
@@ -61,7 +61,7 @@ const products = response.data;
61
61
### Functional
62
62
63
63
``` ts
64
- import { getJSON , postJSON } from " @foundatio /fetchclient" ;
64
+ import { getJSON , postJSON } from " @foundatiofx /fetchclient" ;
65
65
66
66
type Product = { id: number ; title: string };
67
67
type Products = { products: Product [] };
@@ -81,7 +81,7 @@ const product = await getJSON<Product>(
81
81
### Model Validator
82
82
83
83
``` ts
84
- import { FetchClient , setModelValidator } from " @foundatio /fetchclient" ;
84
+ import { FetchClient , setModelValidator } from " @foundatiofx /fetchclient" ;
85
85
86
86
setModelValidator (async (data : object | null ) => {
87
87
// use zod or any other validator
@@ -115,7 +115,7 @@ if (!response.ok) {
115
115
### Caching
116
116
117
117
``` ts
118
- import { FetchClient } from " @foundatio /fetchclient" ;
118
+ import { FetchClient } from " @foundatiofx /fetchclient" ;
119
119
120
120
type Todo = { userId: number ; id: number ; title: string ; completed: boolean };
121
121
@@ -135,7 +135,7 @@ client.cache.delete(["todos", "1"]);
135
135
### Middleware
136
136
137
137
``` ts
138
- import { FetchClient , useMiddleware } from " @foundatio /fetchclient" ;
138
+ import { FetchClient , useMiddleware } from " @foundatiofx /fetchclient" ;
139
139
140
140
type Products = {
141
141
products: Array <{ id: number ; name: string }>;
@@ -156,7 +156,7 @@ const response = await client.getJSON<Products>(
156
156
### Rate Limiting
157
157
158
158
``` ts
159
- import { FetchClient , useRateLimit } from " @foundatio /fetchclient" ;
159
+ import { FetchClient , useRateLimit } from " @foundatiofx /fetchclient" ;
160
160
161
161
// Enable rate limiting globally with 100 requests per minute
162
162
useRateLimit ({
@@ -173,7 +173,7 @@ const response = await client.getJSON(
173
173
### Request Timeout
174
174
175
175
``` ts
176
- import { FetchClient } from " @foundatio /fetchclient" ;
176
+ import { FetchClient } from " @foundatiofx /fetchclient" ;
177
177
178
178
const client = new FetchClient ();
179
179
@@ -196,7 +196,7 @@ const response2 = await client.getJSON(
196
196
### Error Handling
197
197
198
198
``` ts
199
- import { FetchClient } from " @foundatio /fetchclient" ;
199
+ import { FetchClient } from " @foundatiofx /fetchclient" ;
200
200
201
201
const client = new FetchClient ();
202
202
@@ -228,7 +228,7 @@ const response = await client.getJSON(
228
228
### Authentication
229
229
230
230
``` ts
231
- import { FetchClient , setAccessTokenFunc } from " @foundatio /fetchclient" ;
231
+ import { FetchClient , setAccessTokenFunc } from " @foundatiofx /fetchclient" ;
232
232
233
233
// Set global access token function
234
234
setAccessTokenFunc (() => localStorage .getItem (" token" ));
@@ -241,7 +241,7 @@ const response = await client.getJSON(`https://api.example.com/data`);
241
241
### Base URL
242
242
243
243
``` ts
244
- import { FetchClient , setBaseUrl } from " @foundatio /fetchclient" ;
244
+ import { FetchClient , setBaseUrl } from " @foundatiofx /fetchclient" ;
245
245
246
246
// Set global base URL
247
247
setBaseUrl (" https://api.example.com" );
@@ -254,7 +254,7 @@ const response = await client.getJSON(`/users/123`);
254
254
### Loading State
255
255
256
256
``` ts
257
- import { FetchClient } from " @foundatio /fetchclient" ;
257
+ import { FetchClient } from " @foundatiofx /fetchclient" ;
258
258
259
259
const client = new FetchClient ();
260
260
0 commit comments