UNPKG

@metis-w/api-client

Version:

Modern TypeScript HTTP API client with dynamic routes, parameterized endpoints, interceptors, and advanced features

53 lines 1.61 kB
import { APIClient } from "."; import { APIConfig, APIResponse } from "../types"; import { CacheManager } from "../libs/managers"; /** * Interface for dynamic route functions */ export interface DynamicRoute { /** * Call the route as an action with data */ (data?: any): Promise<APIResponse>; /** * Create a parameterized route with an ID */ (id: string | number): DynamicParameterizedRoute; } /** * Interface for parameterized routes (e.g., api.users(123).action() or api.users(123)()) */ export interface DynamicParameterizedRoute { /** * Call the parameterized route directly * - No payload: GET /resource/id * - With payload: PUT /resource/id (default for updates) */ (payload?: any, queryParams?: Record<string, string>): Promise<APIResponse>; /** * Call specific actions on the parameterized route */ [action: string]: (data?: any, queryParams?: Record<string, string>) => Promise<APIResponse>; } /** * Type-safe DynamicClient interface */ export interface IDynamicClient extends APIClient { [route: string]: any; cache: CacheManager; destroy(): void; } export declare class DynamicClient extends APIClient { private cacheManager; /** * Returns the cache manager for dynamic routes, actions, and parameterized routes. * This allows access to cached routes and actions. */ get cache(): CacheManager; constructor(config: APIConfig); /** * Destroys the dynamic client and cleans up all caches */ destroy(): void; } //# sourceMappingURL=dynamic-client.d.ts.map