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 typepath
- API url pathmethod
- HTTP request methoddescription
- API descriptioncategory
- Optional, API categoryschema
- Optional, validate schem with zodneedAuth
- Optional, need auth or no needdisabled
- Optional, is disabled or notheaders
- Optional, custom headersparamsInUrl
- Optional, value is{}
or:
, generate url with params in url.isGet
- Optional, Force the API to generate fetch or update hook forSWR
/ReactQuery
hooks, because sometimes the backend API are allpost
method