@allkit/http-client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/README.md +1 -0
- package/dist/adapter/base.d.ts +2 -0
- package/dist/adapter/taro.d.ts +2 -0
- package/dist/constants.d.ts +13 -0
- package/dist/core/Http.d.ts +26 -0
- package/dist/core/config.d.ts +7 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/interceptor.d.ts +17 -0
- package/dist/core/request.d.ts +73 -0
- package/dist/http-client.es.js +1864 -0
- package/dist/http-client.umd.js +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/package.json +22 -0
- package/dist/types.d.ts +69 -0
- package/dist/utils/index.d.ts +15 -0
- package/package.json +33 -0
- package/scripts/build.mjs +94 -0
- package/skill/SKILL.md +37 -0
- package/skill/examples/api.ts +50 -0
- package/skill/references/delete.md +17 -0
- package/skill/references/get.md +28 -0
- package/skill/references/patch.md +18 -0
- package/skill/references/post.md +27 -0
- package/skill/references/put.md +18 -0
- package/src/adapter/base.ts +1 -0
- package/src/adapter/taro.ts +35 -0
- package/src/constants.ts +20 -0
- package/src/core/Http.ts +82 -0
- package/src/core/config.ts +51 -0
- package/src/core/index.ts +6 -0
- package/src/core/interceptor.ts +98 -0
- package/src/core/request.ts +75 -0
- package/src/index.ts +18 -0
- package/src/types.ts +82 -0
- package/src/utils/index.ts +36 -0
- package/tsconfig.json +26 -0
- package/types/global.d.ts +16 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# http 网络请求库
|
package/dist/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# http 网络请求库
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const EnumMethod: {
|
|
2
|
+
readonly GET: "get";
|
|
3
|
+
readonly POST: "post";
|
|
4
|
+
readonly put: "put";
|
|
5
|
+
readonly PATCH: "patch";
|
|
6
|
+
readonly DELETE: "delete";
|
|
7
|
+
};
|
|
8
|
+
export declare enum EnumContentType {
|
|
9
|
+
URL_ENCODED = "application/x-www-form-urlencoded",
|
|
10
|
+
JSON = "application/json",
|
|
11
|
+
FORM = "multipart/form-data",
|
|
12
|
+
TEXT = "text/html"
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HttpClient, HttpRequestConfig, HttpRequestConfigWrap } from '../types';
|
|
2
|
+
declare class Http {
|
|
3
|
+
private static _instance;
|
|
4
|
+
private _client;
|
|
5
|
+
defaultReqConfig: HttpRequestConfig;
|
|
6
|
+
constructor(reqConfig: HttpRequestConfig);
|
|
7
|
+
static get instance(): Http;
|
|
8
|
+
/** 初始化配置 */
|
|
9
|
+
static init(config?: HttpRequestConfigWrap): Http;
|
|
10
|
+
createHttp(): void;
|
|
11
|
+
/** 设置baseUrl */
|
|
12
|
+
setBaseURL(baseURL: string): void;
|
|
13
|
+
setAdapter(option: Record<string, any>): void;
|
|
14
|
+
get client(): HttpClient;
|
|
15
|
+
/** 通用请求 */
|
|
16
|
+
request<T = any>(reqConfig: HttpRequestConfigWrap): Promise<T>;
|
|
17
|
+
/** get请求 */
|
|
18
|
+
static get<T = any>(reqConfig: HttpRequestConfigWrap): Promise<T>;
|
|
19
|
+
/** post请求 */
|
|
20
|
+
static post<T = any>(reqConfig: HttpRequestConfigWrap): Promise<T>;
|
|
21
|
+
/** put 请求 */
|
|
22
|
+
static put<T = any>(reqConfig: HttpRequestConfigWrap): Promise<T>;
|
|
23
|
+
/** delete 请求 */
|
|
24
|
+
static delete<T = any>(reqConfig: HttpRequestConfigWrap): Promise<T>;
|
|
25
|
+
}
|
|
26
|
+
export default Http;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HttpRequestConfig, HttpResponse } from '../types';
|
|
2
|
+
export declare const defaultInterceptors: () => {
|
|
3
|
+
response: (res: HttpResponse) => Promise<unknown>;
|
|
4
|
+
rejectResponse: (res: any) => Promise<never>;
|
|
5
|
+
};
|
|
6
|
+
/** 默认的配置 */
|
|
7
|
+
export declare const defaultConfig: HttpRequestConfig;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { HttpInterceptor, HttpRequestConfig, HttpResponse } from '../types';
|
|
3
|
+
export declare function mergeInterceptor(httpInterceptor?: Partial<HttpInterceptor>): ({
|
|
4
|
+
callback: import('..').HttpInterceptorRequest;
|
|
5
|
+
type: string;
|
|
6
|
+
} | {
|
|
7
|
+
callback: import('..').HttpInterceptorResponse;
|
|
8
|
+
type: string;
|
|
9
|
+
} | {
|
|
10
|
+
callback: import('..').HttpInterceptorReject;
|
|
11
|
+
type: string;
|
|
12
|
+
})[];
|
|
13
|
+
/**
|
|
14
|
+
* 处理拦截器
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleInterceptor(request: AxiosInstance, reqConfig: HttpRequestConfig): void;
|
|
17
|
+
export declare function commonResponseErrorMsg(res: HttpResponse): string;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { HttpRequestConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 创建请求头
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseHeaders(config: HttpRequestConfig): Record<string, any>;
|
|
6
|
+
/**
|
|
7
|
+
* 创建请求体
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseBody(config: HttpRequestConfig): {
|
|
10
|
+
data: {};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 处理转换请求
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseRequest(config: HttpRequestConfig): {
|
|
16
|
+
data: {};
|
|
17
|
+
headers: Record<string, any>;
|
|
18
|
+
token?: string | (() => string);
|
|
19
|
+
userId?: string | (() => string);
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
loadingOption?: {
|
|
22
|
+
show: () => void;
|
|
23
|
+
hide: () => void;
|
|
24
|
+
};
|
|
25
|
+
ignoreToast?: boolean | Array<number | string>;
|
|
26
|
+
showErrorMsg?: (msg: string) => void;
|
|
27
|
+
casToken?: boolean;
|
|
28
|
+
interceptors?: Partial<import('..').HttpInterceptor>;
|
|
29
|
+
url?: string;
|
|
30
|
+
method?: import('axios').Method | string;
|
|
31
|
+
baseURL?: string;
|
|
32
|
+
transformRequest?: import('axios').AxiosRequestTransformer | import('axios').AxiosRequestTransformer[];
|
|
33
|
+
transformResponse?: import('axios').AxiosResponseTransformer | import('axios').AxiosResponseTransformer[];
|
|
34
|
+
params?: any;
|
|
35
|
+
paramsSerializer?: import('axios').ParamsSerializerOptions | import('axios').CustomParamsSerializer;
|
|
36
|
+
timeout?: number;
|
|
37
|
+
timeoutErrorMessage?: string;
|
|
38
|
+
withCredentials?: boolean;
|
|
39
|
+
adapter?: (string | import('axios').AxiosAdapter) | (string | import('axios').AxiosAdapter)[];
|
|
40
|
+
auth?: import('axios').AxiosBasicCredentials;
|
|
41
|
+
responseType?: import('axios').ResponseType;
|
|
42
|
+
responseEncoding?: import('axios').responseEncoding | string;
|
|
43
|
+
xsrfCookieName?: string;
|
|
44
|
+
xsrfHeaderName?: string;
|
|
45
|
+
onUploadProgress?: (progressEvent: import('axios').AxiosProgressEvent) => void;
|
|
46
|
+
onDownloadProgress?: (progressEvent: import('axios').AxiosProgressEvent) => void;
|
|
47
|
+
maxContentLength?: number;
|
|
48
|
+
validateStatus?: ((status: number) => boolean) | null;
|
|
49
|
+
maxBodyLength?: number;
|
|
50
|
+
maxRedirects?: number;
|
|
51
|
+
maxRate?: number | [number, number];
|
|
52
|
+
beforeRedirect?: (options: Record<string, any>, responseDetails: {
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
statusCode: import('axios').HttpStatusCode;
|
|
55
|
+
}) => void;
|
|
56
|
+
socketPath?: string | null;
|
|
57
|
+
transport?: any;
|
|
58
|
+
httpAgent?: any;
|
|
59
|
+
httpsAgent?: any;
|
|
60
|
+
proxy?: import('axios').AxiosProxyConfig | false;
|
|
61
|
+
cancelToken?: import('axios').CancelToken;
|
|
62
|
+
decompress?: boolean;
|
|
63
|
+
transitional?: import('axios').TransitionalOptions;
|
|
64
|
+
signal?: import('axios').GenericAbortSignal;
|
|
65
|
+
insecureHTTPParser?: boolean;
|
|
66
|
+
env?: {
|
|
67
|
+
FormData?: new (...args: any[]) => object;
|
|
68
|
+
};
|
|
69
|
+
formSerializer?: import('axios').FormSerializerOptions;
|
|
70
|
+
family?: import('axios').AddressFamily;
|
|
71
|
+
lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: import('axios').LookupAddress | import('axios').LookupAddress[], family?: import('axios').AddressFamily) => void) => void) | ((hostname: string, options: object) => Promise<[address: import('axios').LookupAddressEntry | import('axios').LookupAddressEntry[], family?: import('axios').AddressFamily] | import('axios').LookupAddress>);
|
|
72
|
+
withXSRFToken?: boolean | ((config: import('axios').InternalAxiosRequestConfig) => boolean | undefined);
|
|
73
|
+
};
|