@tkrotoff/fetch
Version:
Fetch wrapper
58 lines (57 loc) • 2.14 kB
TypeScript
/**
* `Promise<`[`Response`](https://fetch.spec.whatwg.org/#response)`>` with added methods from [`Body`](https://fetch.spec.whatwg.org/#body-mixin).
*/
export type ResponsePromiseWithBodyMethods = Promise<Response> & Pick<Body, 'arrayBuffer' | 'blob' | 'formData' | /*'json' |*/ 'text'> & {
json(): Promise<unknown>;
};
export declare const jsonMimeType = "application/json";
export declare function isJSONResponse(response: Response): boolean;
export type Init = Omit<RequestInit, 'method' | 'body'>;
export type Config = {
init: Init;
};
export declare const defaults: Config;
/**
* Performs a HTTP `GET` request.
*/
export declare function get(input: RequestInfo | URL, init?: Init): ResponsePromiseWithBodyMethods;
/**
* Performs a HTTP `POST` request.
*
* @see {@link postJSON()}
*/
export declare function post<T extends BodyInit>(input: RequestInfo | URL, body?: T, init?: Init): ResponsePromiseWithBodyMethods;
/**
* Performs a HTTP `POST` request with a JSON body.
*
* @see {@link post()}
*/
export declare function postJSON<T extends object>(input: RequestInfo | URL, body: T, init?: Init): ResponsePromiseWithBodyMethods;
/**
* Performs a HTTP `PUT` request.
*
* @see {@link putJSON()}
*/
export declare function put<T extends BodyInit>(input: RequestInfo | URL, body?: T, init?: Init): ResponsePromiseWithBodyMethods;
/**
* Performs a HTTP `PUT` request with a JSON body.
*
* @see {@link put()}
*/
export declare function putJSON<T extends object>(input: RequestInfo | URL, body: T, init?: Init): ResponsePromiseWithBodyMethods;
/**
* Performs a HTTP `PATCH` request.
*
* @see {@link patchJSON()}
*/
export declare function patch<T extends BodyInit>(input: RequestInfo | URL, body?: T, init?: Init): ResponsePromiseWithBodyMethods;
/**
* Performs a HTTP `PATCH` request with a JSON body.
*
* @see {@link patch()}
*/
export declare function patchJSON<T extends object>(input: RequestInfo | URL, body: T, init?: Init): ResponsePromiseWithBodyMethods;
/**
* Performs a HTTP `DELETE` request.
*/
export declare function del(input: RequestInfo | URL, init?: Init): ResponsePromiseWithBodyMethods;