kayto_ts 0.1.9 → 0.1.11

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.
Files changed (2) hide show
  1. package/README.md +63 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  [📦 npm: kayto_ts](https://www.npmjs.com/package/kayto_ts)
4
4
 
5
- 🚀 Build robust API integrations faster with `kayto_ts`.
5
+ `kayto_ts` is a type-safe HTTP client that works in pair with `kayto` 🦀 (Rust).
6
+
7
+ `kayto` generates `schema.ts` from your OpenAPI spec, and `kayto_ts` uses that schema to provide strongly-typed requests, responses, and hooks across any TypeScript platform: browser, Bun, Node.js, Deno, and more.
6
8
 
7
9
  - 🔒 End-to-end type safety for `method + path + params + body + response`
8
10
  - ⚡ Zero-boilerplate HTTP client usage with generated schema types
@@ -224,6 +226,66 @@ const clientWithHooks = clientApi<CatsEndpoints>({
224
226
  });
225
227
  ```
226
228
 
229
+ ## Success Handling (Cats API)
230
+
231
+ ```ts
232
+ async function fetchCatsUI() {
233
+ let loading = true;
234
+
235
+ try {
236
+ const result = await client.get("/api/cats");
237
+
238
+ if (!result.ok) {
239
+ throw result.error;
240
+ }
241
+
242
+ const cats = result.responses[200];
243
+
244
+ if (!cats) {
245
+ throw new Error("Cats response is empty");
246
+ }
247
+
248
+ return cats;
249
+ } catch (error) {
250
+ // UI can show toast/snackbar here
251
+ throw error;
252
+ } finally {
253
+ loading = false;
254
+ }
255
+ }
256
+ ```
257
+
258
+ ```ts
259
+ async function createCatUI() {
260
+ let loading = true;
261
+
262
+ try {
263
+ const result = await client.post("/api/cats", {
264
+ body: {
265
+ name: "Milo",
266
+ age: 2,
267
+ },
268
+ });
269
+
270
+ if (!result.ok) {
271
+ throw result.error;
272
+ }
273
+
274
+ const created = result.responses[201] ?? result.responses[200];
275
+
276
+ if (!created) {
277
+ throw new Error("Create cat payload is empty");
278
+ }
279
+
280
+ return created;
281
+ } catch (error) {
282
+ throw error;
283
+ } finally {
284
+ loading = false;
285
+ }
286
+ }
287
+ ```
288
+
227
289
  ## Error Handling
228
290
 
229
291
  All requests return a discriminated union:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kayto_ts",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Type-safe HTTP client for working with kayto-generated endpoint schemas.",
5
5
  "repository": {
6
6
  "type": "git",