Documentation
Guide
APIConfig

APIConfig

APIConfig defined the basic configuration specifications of API:

src/shared/tsdk-types.ts
import * as z from 'zod';
 
export const APITypes = {
  user: 'user',
  admin: 'admin',
  common: 'common',
} as const;
 
export const APITypesKey = Object.keys(APITypes).filter((item) => item !== APITypes.common);
 
export type APIType = keyof typeof APITypes;
 
export interface APIConfig {
  /** The API type. Like: user side or admin side. */
  type: APIType;
  /** The API path */
  path: string;
  method: 'get' | 'post' | 'delete' | 'put' | 'patch' | 'head' | 'options';
  /** Request data validate scheme */
  schema?: z.ZodTypeAny;
  /** The API need auth? Default is false */
  needAuth?: boolean;
  /** The API disabled? Default is false */
  disabled?: boolean;
  /** The API description */
  description: string;
  /** The API category */
  category?: string;
 
  /** custom headers for client */
  headers?: { [key: string]: any };
  /**
   * is params in url? for generate API sdk base documentation.
   * default undefined,
   * if `:`, will support `/api/:a/b/:c`,
   * if `{}`, will support `/api/{a}/b/{c}`,
   * and will replace with data with {a: 1, c: 2} to `/api/1/b/2`  */
  paramsInUrl?: ':' | '{}';
  /** Force the API is fetch data, for sometimes the backend API are all `post` method */
  isGet?: boolean;
}

Fields

  • type - API type
  • path - API url path
  • method - HTTP request method
  • description - API description
  • category - Optional, API category
  • schema - Optional, validate schem with zod
  • needAuth - Optional, need auth or no need
  • disabled - Optional, is disabled or not
  • headers - Optional, custom headers
  • paramsInUrl - Optional, value is {} or :, generate url with params in url.
  • isGet - Optional, Force the API to generate fetch or update hook for SWR / ReactQuery hooks, because sometimes the backend API are all post method