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
+160Lines changed: 160 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,166 @@ Options:
74
74
75
75
Basically, let's focus on having a fast and typesafe API client generation instead.
76
76
77
+
## Usage Examples
78
+
79
+
### API Client Setup
80
+
81
+
The generated client is headless - you need to provide your own fetcher. Here are ready-to-use examples:
82
+
83
+
-**[Basic API Client](packages/typed-openapi/API_CLIENT_EXAMPLES.md#basic-api-client-api-client-examplets)** - Simple, dependency-free wrapper
84
+
-**[Validating API Client](packages/typed-openapi/API_CLIENT_EXAMPLES.md#validating-api-client-api-client-with-validationts)** - With request/response validation
85
+
86
+
### Type-Safe Error Handling
87
+
88
+
The generated client includes discriminated union types for handling both success and error responses:
89
+
90
+
```typescript
91
+
// With withResponse: true, get full response details
92
+
const result =awaitapi.get("/users/{id}", {
93
+
path: { id: "123" },
94
+
withResponse: true
95
+
});
96
+
97
+
if (result.ok) {
98
+
// result.data is typed as the success response
99
+
console.log("User:", result.data.name);
100
+
// result.status is typed as success status codes (200, 201, etc.)
101
+
} else {
102
+
// result.error is typed based on documented error responses
103
+
if (result.status===404) {
104
+
console.log("User not found:", result.error.message);
0 commit comments