feat(api): generate TypeScript API client from OpenAPI specification
Create type-safe TypeScript API client automatically generated from the OpenAPI specification. Includes generated schema types and documented client wrapper for type-safe backend communication. Ref: T008 (specs/001-modbus-relay-control)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* API client for the STA backend.
|
||||
*
|
||||
* This client is generated from the OpenAPI specification and provides
|
||||
* type-safe access to all backend endpoints.
|
||||
*
|
||||
* Usage:
|
||||
* ```typescript
|
||||
* import { apiClient } from '@/api/client';
|
||||
*
|
||||
* const { data, error } = await apiClient.GET('/api/health');
|
||||
* ```
|
||||
*/
|
||||
|
||||
import createClient from 'openapi-fetch';
|
||||
import type { paths } from './schema';
|
||||
|
||||
// Get the API base URL from environment variables or default to localhost
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3100';
|
||||
|
||||
/**
|
||||
* Typed API client instance.
|
||||
*
|
||||
* All requests are type-checked against the OpenAPI schema.
|
||||
*/
|
||||
export const apiClient = createClient<paths>({ baseUrl: API_BASE_URL });
|
||||
|
||||
/**
|
||||
* Re-export the types for convenience
|
||||
*/
|
||||
export type { paths, components } from './schema';
|
||||
Reference in New Issue
Block a user