### Make Requests Using Path-Based Methods Source: https://context7.com/julien-r44/tuyau/llms.txt Use raw URL patterns with methods like `get`, `post`, `put`, `patch`, `delete`, and `head`. This is useful when you know the pattern but prefer not to traverse the route tree, or when calling from generic utilities. Requests are typed against the route registry by pattern. ```typescript // GET /users — typed against the route registry by pattern const users = await tuyau.get('/users', { query: { email: 'foo@example.com' }, }) // GET /users/:id const user = await tuyau.get('/users/:id', { params: { id: '42' }, query: { foo: 'bar' }, }) // POST /auth/login const session = await tuyau.post('/auth/login', { body: { email: 'user@example.com', password: 'secret' }, }) // DELETE /posts/:id await tuyau.delete('/posts/:id', { params: { id: '10' } }) // Nested params await tuyau.get('/posts/:postId/comments/:commentId/likes/:likeId', { params: { postId: '1', commentId: '2', likeId: '3' }, query: { foo: 'bar' }, }) ``` -------------------------------- ### Handle errors with TuyauPromise.safe() Source: https://context7.com/julien-r44/tuyau/llms.txt Use `.safe()` to get a `[data, null] | [null, TuyauError]` tuple instead of throwing. This enables Go-style error handling without try/catch blocks. Check for errors before accessing data. ```typescript const [data, error] = await tuyau.api.auth.login({ body: { email: 'user@example.com', password: 'wrong' }, }).safe() if (error) { if (error.isValidationError()) { // error.response is typed as { errors: SimpleError[] } console.error('Validation failed:', error.response.errors) } else if (error.isStatus(401)) { console.error('Unauthorized:', error.response) } else if (error.kind === 'network') { console.error('Network error:', error.message) } else { console.error(`HTTP ${error.status}:`, error.response) } return } // data is fully typed — no null checks needed here console.log('Logged in:', data.token) ``` -------------------------------- ### Initialize Tuyau Client with createTuyau Source: https://context7.com/julien-r44/tuyau/llms.txt Factory function to initialize the Tuyau HTTP client. Pass the generated registry, base URL, and optional ky options like headers, hooks, and retry configurations. ```typescript import { createTuyau } from '@tuyau/core/client' import { registry } from './tuyau/index.ts' // generated registry const tuyau = createTuyau({ baseUrl: 'http://localhost:3333', registry, // Optional: default headers applied to every request headers: { 'X-App-Version': '1.0' }, // Optional: ky lifecycle hooks hooks: { beforeRequest: [ (request) => { const token = localStorage.getItem('auth_token') if (token) request.headers.set('Authorization', `Bearer ${token}`) }, ], }, // Optional: retry configuration retry: { limit: 2 }, }) ``` -------------------------------- ### createTuyauVueQueryClient Source: https://context7.com/julien-r44/tuyau/llms.txt Creates a typesafe TanStack Vue Query client with the same API surface as the React Query client, adapted for Vue's Composition API. ```APIDOC ## `createTuyauVueQueryClient` — TanStack Vue Query integration Creates a typesafe TanStack Vue Query client with the same API surface as the React Query client, adapted for Vue's Composition API. ```typescript import { createTuyau } from '@tuyau/core/client' import { createTuyauVueQueryClient } from '@tuyau/vue-query' import { useQuery, useMutation } from '@tanstack/vue-query' import { registry } from './tuyau/index.ts' const tuyau = createTuyau({ baseUrl: 'http://localhost:3333', registry }) const api = createTuyauVueQueryClient({ client: tuyau }) // In a Vue component