UNPKG

guardz-axios

Version:

Type-safe HTTP client built on top of Axios with runtime validation using guardz. Part of the guardz ecosystem for comprehensive TypeScript type safety.

31 lines 1.7 kB
import { AxiosInstance } from "axios"; import type { AxiosRequestConfig } from "axios"; import type { TypeGuardFn } from "guardz"; import type { SafeRequestConfig } from "../types/SafeRequestConfig"; import type { SafeRequestResult } from "../types/SafeRequestResult"; import type { SafeApiContextConfig } from "../types/SafeApiContextConfig"; /** * Pattern 4: Context/Provider (React style) * Usage: const safeApi = createSafeApiContext({ baseURL: '...', defaultTolerance: false }); * const result = await safeApi.get('/users/1', { guard: isUser }); */ export declare function createSafeApiContext(contextConfig?: SafeApiContextConfig): { get: <T>(url: string, config: { guard: TypeGuardFn<T>; } & Partial<SafeRequestConfig<T>>, axiosConfig?: AxiosRequestConfig) => Promise<SafeRequestResult<T>>; post: <T>(url: string, data: any, config: { guard: TypeGuardFn<T>; } & Partial<SafeRequestConfig<T>>, axiosConfig?: AxiosRequestConfig) => Promise<SafeRequestResult<T>>; put: <T>(url: string, data: any, config: { guard: TypeGuardFn<T>; } & Partial<SafeRequestConfig<T>>, axiosConfig?: AxiosRequestConfig) => Promise<SafeRequestResult<T>>; patch: <T>(url: string, data: any, config: { guard: TypeGuardFn<T>; } & Partial<SafeRequestConfig<T>>, axiosConfig?: AxiosRequestConfig) => Promise<SafeRequestResult<T>>; delete: <T>(url: string, config: { guard: TypeGuardFn<T>; } & Partial<SafeRequestConfig<T>>, axiosConfig?: AxiosRequestConfig) => Promise<SafeRequestResult<T>>; safe: () => import("..").SafeRequestBuilder<unknown>; instance: AxiosInstance; }; //# sourceMappingURL=createSafeApiContext.d.ts.map