@stacksjs/api 0.70.22 → 0.70.25
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 +114 -0
- package/dist/index.js +1 -4899
- package/dist/src/fetcher.d.ts +42 -0
- package/dist/src/generate-openapi.d.ts +31 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/resource.d.ts +144 -0
- package/package.json +14 -8
- package/dist/generate-openapi.d.ts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/ofetch.d.ts +0 -103
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Stacks Fetcher
|
|
2
|
+
|
|
3
|
+
A simple, powerful HTTP client that wraps the fetch API with a more elegant interface and better TypeScript support.
|
|
4
|
+
|
|
5
|
+
## ☘️ Features
|
|
6
|
+
|
|
7
|
+
- 🚀 Simple, elegant API
|
|
8
|
+
- 💪 Full TypeScript support
|
|
9
|
+
- 🔄 JSON handling by default
|
|
10
|
+
- 📦 Zero dependencies (uses native fetch)
|
|
11
|
+
- 🎯 Type-safe requests and responses
|
|
12
|
+
|
|
13
|
+
## 🤖 Usage
|
|
14
|
+
|
|
15
|
+
### Basic Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// Simple GET request
|
|
19
|
+
const response = await fetcher.get('/users')
|
|
20
|
+
console.log(response.data)
|
|
21
|
+
|
|
22
|
+
// Simple POST request
|
|
23
|
+
const response = await fetcher.post('/users', {
|
|
24
|
+
name: 'John',
|
|
25
|
+
email: 'john@example.com'
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Type-Safe Requests
|
|
30
|
+
|
|
31
|
+
The fetcher is built with TypeScript in mind and provides full type safety for both requests and responses:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Define your types
|
|
35
|
+
interface User {
|
|
36
|
+
id: number
|
|
37
|
+
name: string
|
|
38
|
+
email: string
|
|
39
|
+
created_at: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// GET with array response type
|
|
43
|
+
const { data: users } = await fetcher.get<User[]>('/users')
|
|
44
|
+
users.forEach(user => console.log(user.name)) // TypeScript knows name exists
|
|
45
|
+
|
|
46
|
+
// GET single item
|
|
47
|
+
const { data: user } = await fetcher.get<User>('/users/1')
|
|
48
|
+
console.log(user.id) // TypeScript knows id exists
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Type-Safe POST Requests
|
|
52
|
+
|
|
53
|
+
You can type both the request data and response:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
interface CreateUserRequest {
|
|
57
|
+
name: string
|
|
58
|
+
email: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface User extends CreateUserRequest {
|
|
62
|
+
id: number
|
|
63
|
+
created_at: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { data: newUser } = await fetcher.post<User, CreateUserRequest>('/users', {
|
|
67
|
+
name: 'John', // TypeScript will error if we miss required fields
|
|
68
|
+
email: 'john@example.com'
|
|
69
|
+
})
|
|
70
|
+
console.log(newUser.created_at) // TypeScript knows created_at exists
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Response Structure
|
|
74
|
+
|
|
75
|
+
All fetcher methods return a consistent response structure:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
interface FetcherResponse<T> {
|
|
79
|
+
data: T // The response data (typed as T)
|
|
80
|
+
status: number // HTTP status code
|
|
81
|
+
headers: Headers // Response headers
|
|
82
|
+
ok: boolean // Whether the request was successful
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 🧪 Testing
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
bun test
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 📈 Changelog
|
|
93
|
+
|
|
94
|
+
Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
|
|
95
|
+
|
|
96
|
+
## 🚜 Contributing
|
|
97
|
+
|
|
98
|
+
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
|
|
99
|
+
|
|
100
|
+
## 🏝 Community
|
|
101
|
+
|
|
102
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
103
|
+
|
|
104
|
+
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
|
|
105
|
+
|
|
106
|
+
For casual chit-chat with others using this package:
|
|
107
|
+
|
|
108
|
+
[Join the Stacks Discord Server](https://discord.gg/stacksjs)
|
|
109
|
+
|
|
110
|
+
## 📄 License
|
|
111
|
+
|
|
112
|
+
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
|
|
113
|
+
|
|
114
|
+
Made with 💙
|