@amanooo/fetch
Version:
custom fetch
32 lines (31 loc) • 1.2 kB
TypeScript
interface RetryOptions {
retries?: number;
timeout?: number;
delay?: number;
}
export default class Fetch {
static headers: HeadersInit;
static credentials: RequestCredentials;
static debug: boolean;
static retryOpts: RetryOptions;
static get(url: string, params?: Object, options?: RequestInit, retryOpts?: RetryOptions): Promise<any>;
static post(url: string, body?: any, options?: RequestInit, retryOpts?: RetryOptions): Promise<any>;
static put(url: string, body?: Object, options?: RequestInit, retryOpts?: RetryOptions): Promise<any>;
static delete(url: string, body?: Object, options?: RequestInit, retryOpts?: RetryOptions): Promise<any>;
static fetch(url: string, options: RequestInit, retryOpts?: RetryOptions): Promise<any>;
}
interface SucessResult<T> {
error: null;
payload: T;
}
interface FailResult<T> {
error: string;
payload: null;
}
export declare type IResultUtil<T = any> = SucessResult<T> | FailResult<T>;
export declare class ResultUtil {
static send(error: string, payload?: any): IResultUtil<any>;
static success(payload: any): IResultUtil;
static fail(error?: string): IResultUtil<any>;
}
export {};