hook-fetch
Version:
A lightweight and modern HTTP request library developed based on the native Fetch API of the browser, providing a user-friendly interface similar to Axios and powerful extensibility.
42 lines (41 loc) • 4.06 kB
TypeScript
import { AnyObject, Generic } from 'typescript-api-pro';
import { BaseOptions, DeleteOptions, GetOptions, HeadOptions, HookFetchPlugin, OptionsOptions, PatchOptions, PostOptions, PutOptions, RequestOptions } from './types';
import { HookFetchRequest } from './utils';
declare class HookFetch<R extends AnyObject = AnyObject, K extends keyof R = 'data', E = AnyObject> {
#private;
constructor({ timeout, baseURL, headers, plugins, withCredentials }: BaseOptions);
use(plugin: HookFetchPlugin<any, any, any, any>): this;
request<T = AnyObject, P = AnyObject, D = AnyObject>(url: string, { timeout, headers, method, params, data, qsArrayFormat, withCredentials, extra }?: RequestOptions<P, D, E>): HookFetchRequest<Generic<R, K, T>, E>;
get<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: GetOptions<P, E>): HookFetchRequest<Generic<R, K, T>, E>;
head<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: HeadOptions<P, E>): HookFetchRequest<Generic<R, K, T>, E>;
options<T = AnyObject, P = AnyObject, D = AnyObject>(url: string, params?: P, options?: OptionsOptions<P, D, E>): HookFetchRequest<Generic<R, K, T>, E>;
delete<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, options?: DeleteOptions<P, D, E>): HookFetchRequest<Generic<R, K, T>, E>;
post<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
upload<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
put<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
patch<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>): HookFetchRequest<Generic<R, K, T>, E>;
abortAll(): void;
}
declare const useRequest: <R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, options?: RequestOptions<P, D, E>) => HookFetchRequest<R, E>;
export declare const request: <R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, options?: RequestOptions<P, D, E>) => HookFetchRequest<R, E>;
export declare const get: <R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: GetOptions<P, E>) => HookFetchRequest<R, E>;
export declare const head: <R = AnyObject, P = AnyObject, E = AnyObject>(url: string, params?: P, options?: HeadOptions<P, E>) => HookFetchRequest<R, E>;
export declare const options: <R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, params?: P, options?: OptionsOptions<P, D, E>) => HookFetchRequest<R, E>;
export declare const del: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, options?: DeleteOptions<P, D, E>) => HookFetchRequest<R, E>;
export declare const post: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>) => HookFetchRequest<R, E>;
export declare const upload: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>) => HookFetchRequest<R, E>;
export declare const put: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>) => HookFetchRequest<R, E>;
export declare const patch: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>) => HookFetchRequest<R, E>;
type ExportDefault = typeof useRequest & {
create: <R extends AnyObject = AnyObject, K extends keyof R = 'data', E = AnyObject>(options: BaseOptions) => (HookFetch<R, K, E>['request'] & HookFetch<R, K, E>);
get: typeof get;
head: typeof head;
options: typeof options;
delete: typeof del;
post: typeof post;
put: typeof put;
patch: typeof patch;
upload: typeof upload;
};
declare const hookFetch: ExportDefault;
export default hookFetch;