endpoint-fetcher 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A type-safe API client builder using the Fetch API with full TypeScript support.
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install fetcher
|
|
8
|
+
npm install endpoint-fetcher
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Features
|
|
@@ -20,7 +20,7 @@ npm install fetcher
|
|
|
20
20
|
## Basic Usage
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
|
-
import { createApiClient, EndpointConfig } from 'fetcher';
|
|
23
|
+
import { createApiClient, EndpointConfig } from 'endpoint-fetcher';
|
|
24
24
|
|
|
25
25
|
type User = { id: string; name: string; email: string };
|
|
26
26
|
|
|
@@ -158,17 +158,17 @@ const api = createApiClient(
|
|
|
158
158
|
const formData = new FormData();
|
|
159
159
|
formData.append('file', input.file);
|
|
160
160
|
formData.append('category', input.category);
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
const response = await fetch('https://api.example.com/upload', {
|
|
163
163
|
method: 'POST',
|
|
164
164
|
body: formData,
|
|
165
165
|
// Note: Don't set Content-Type for FormData
|
|
166
166
|
});
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
if (!response.ok) {
|
|
169
169
|
throw new Error('Upload failed');
|
|
170
170
|
}
|
|
171
|
-
|
|
171
|
+
|
|
172
172
|
return response.json();
|
|
173
173
|
},
|
|
174
174
|
} as EndpointConfig
|
|
@@ -184,11 +184,11 @@ const api = createApiClient(
|
|
|
184
184
|
`https://api.example.com/files/${input.id}`,
|
|
185
185
|
{ method: 'GET' }
|
|
186
186
|
);
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
if (!response.ok) {
|
|
189
189
|
throw new Error('Download failed');
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
|
|
192
192
|
return response.blob();
|
|
193
193
|
},
|
|
194
194
|
} as EndpointConfig<{ id: string }, Blob>,
|
|
@@ -301,7 +301,7 @@ try {
|
|
|
301
301
|
### 10. Complex Example - Full API Client
|
|
302
302
|
|
|
303
303
|
```typescript
|
|
304
|
-
import { createApiClient, EndpointConfig } from 'fetcher';
|
|
304
|
+
import { createApiClient, EndpointConfig } from 'endpoint-fetcher';
|
|
305
305
|
|
|
306
306
|
// Types
|
|
307
307
|
type User = { id: string; name: string; email: string };
|
|
@@ -358,12 +358,12 @@ const api = createApiClient(
|
|
|
358
358
|
q: input.query,
|
|
359
359
|
...(input.limit && { limit: input.limit.toString() }),
|
|
360
360
|
});
|
|
361
|
-
|
|
361
|
+
|
|
362
362
|
const response = await fetch(
|
|
363
363
|
`https://api.example.com${path}?${params}`,
|
|
364
364
|
{ method: 'GET' }
|
|
365
365
|
);
|
|
366
|
-
|
|
366
|
+
|
|
367
367
|
if (!response.ok) throw new Error('Search failed');
|
|
368
368
|
return response.json();
|
|
369
369
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "endpoint-fetcher",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Type-safe API client builder using fetch",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"tsup": "^8.5.1",
|
|
53
53
|
"typescript": "^5.0.0"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|