# Getting Started This guide will help you set up and start using `@qualisero/openapi-endpoint` in your Vue project. ## Prerequisites - Vue 3.3 or higher - TanStack Vue Query 5.90 or higher - Axios 1.12 or higher - An OpenAPI specification (JSON or YAML) for your API ## Installation ```bash npm install @qualisero/openapi-endpoint ``` Or with yarn: ```bash yarn add @qualisero/openapi-endpoint ``` ## Step 1: Generate Types and Operations This package includes a CLI tool to generate TypeScript types and operation definitions from your OpenAPI specification. ### From a local file ```bash npx @qualisero/openapi-endpoint ./api/openapi.json ./src/generated ``` ### From a remote URL ```bash npx @qualisero/openapi-endpoint https://api.example.com/openapi.json ./src/api ``` This will generate three files: - `openapi-types.ts` - TypeScript type definitions for your API - `api-operations.ts` - Operation definitions combining metadata and types - `api-enums.ts` - Type-safe enum constants from your API schema ## Step 2: Configure Axios Create an axios instance with your API configuration: ```typescript // api/axios.ts import axios from 'axios' export const axiosInstance = axios.create({ baseURL: 'https://api.example.com', timeout: 10000, headers: { 'Content-Type': 'application/json', }, }) // Add authentication interceptor if needed axiosInstance.interceptors.request.use((config) => { const token = localStorage.getItem('authToken') if (token) { config.headers.Authorization = `Bearer ${token}` } return config }) ``` ## Step 3: Initialize the API Client Create a typed API client using the generated `createApiClient` factory: ```typescript // api/init.ts import { createApiClient } from '@qualisero/openapi-endpoint' import { axiosInstance } from './axios' const api = createApiClient(axiosInstance) export { api } ``` ### Optional: Custom QueryClient If you need to customize the TanStack Query client, you can provide your own: ```typescript // api/init.ts import { createApiClient } from '@qualisero/openapi-endpoint' import { QueryClient } from '@tanstack/vue-query' import { axiosInstance } from './axios' const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: 5 * 60 * 1000, // 5 minutes retry: 3, }, mutations: { retry: 1, }, }, }) const api = createApiClient(axiosInstance, queryClient) export { api } ``` ## Step 4: Use in Your Components ### Using Queries ```vue ``` ### Using Mutations ```vue ``` ## Using Enum Values The CLI generates type-safe enum constants from your OpenAPI spec: ```vue ``` ## What's Next? - [Queries](./02-queries.md) - Learn about using queries for GET operations - [Mutations](./03-mutations.md) - Learn about mutations for POST/PUT/PATCH/DELETE operations - [Reactive Parameters](./04-reactive-parameters.md) - Learn about reactive query and path parameters - [Cache Management](./06-cache-management.md) - Learn about automatic and manual cache control