@tkrotoff/fetch
Version:
Fetch wrapper
30 lines (29 loc) • 1.66 kB
TypeScript
export interface ResponsePromiseWithBodyMethods extends Promise<Response> {
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
json(): Promise<unknown>;
text(): Promise<string>;
}
export declare const JSON_MIME_TYPE = "application/json";
export declare function isJSONResponse(response: Response): boolean;
export declare type Init = Omit<RequestInit, 'method' | 'body'>;
export declare type Config = {
init: Init;
};
export declare const defaults: Config;
interface ObjectWithEntries {
entries(): IterableIterator<[string, any]>;
}
export declare function entriesToObject<T extends ObjectWithEntries>(object: T): {
[k: string]: any;
};
export declare function get(input: RequestInfo, init?: Init): ResponsePromiseWithBodyMethods;
export declare function postJSON<T extends object>(input: RequestInfo, body: T, init?: Init): ResponsePromiseWithBodyMethods;
export declare function post<T extends BodyInit>(input: RequestInfo, body: T, init?: Init): ResponsePromiseWithBodyMethods;
export declare function putJSON<T extends object>(input: RequestInfo, body: T, init?: Init): ResponsePromiseWithBodyMethods;
export declare function put<T extends BodyInit>(input: RequestInfo, body: T, init?: Init): ResponsePromiseWithBodyMethods;
export declare function patchJSON<T extends object>(input: RequestInfo, body: T, init?: Init): ResponsePromiseWithBodyMethods;
export declare function patch<T extends BodyInit>(input: RequestInfo, body: T, init?: Init): ResponsePromiseWithBodyMethods;
export declare function del(input: RequestInfo, init?: Init): ResponsePromiseWithBodyMethods;
export {};