UNPKG

@coolio/http

Version:
60 lines (59 loc) 2.41 kB
/// <reference types="node" /> import { HttpResponseHeaders } from './httpResponseHeaders'; import TypedArray = NodeJS.TypedArray; import { CFormData } from './formData'; export interface RawHttpResponse { readonly headers: HttpResponseHeaders; readonly ok: boolean; readonly redirected: boolean; readonly status: number; readonly statusText: string; readonly url: string; arrayBuffer(): Promise<ArrayBuffer>; text(): Promise<string>; abort(): void; } export interface HttpResponse<T = any> extends RawHttpResponse { parsedBody(): Promise<T>; } export declare type BodyParser<T = unknown> = (response: RawHttpResponse) => HttpResponse<T>; export declare type BodySerializer = (request: HttpOptions) => NormalizedHttpBody; export declare type HttpFetch<Body> = () => Promise<HttpResponse<Body>>; export declare type HttpBody = object | TypedArray | string; export declare type HttpHeaders = Record<string, string | number | boolean | undefined | null>; export interface HttpInterceptorInterface { onIntercept<Body>(request: HttpFetch<Body>, options: NormalizedHttpOptions): HttpFetch<Body>; } export declare type HttpInterceptorFunction = <Body>(request: HttpFetch<Body>, options: NormalizedHttpOptions) => HttpFetch<Body>; export declare type HttpInterceptor = HttpInterceptorFunction | HttpInterceptorInterface; export declare enum HttpMethod { POST = "POST", GET = "GET", PUT = "PUT", PATCH = "PATCH", DELETE = "DELETE" } export declare type RequestMode = 'navigate' | 'same-origin' | 'no-cors' | 'cors'; export interface HttpRequestOptions { method: HttpMethod; query?: object; mode?: RequestMode; headers?: HttpHeaders; body?: HttpBody; bypassResponseHandler?: boolean; timeout?: number; } export declare type HttpOptions = Partial<HttpRequestOptions>; export declare type NormalizedHttpBody = FormData | CFormData | TypedArray | string | undefined; export interface NormalizedHttpOptions { url: string; query: any; body?: NormalizedHttpBody; method: HttpMethod; headers: Record<string, string>; mode?: RequestMode; bypassResponseHandler?: boolean; timeout: number; } export declare type HttpRequestHandler = (requestOptions: NormalizedHttpOptions) => Promise<RawHttpResponse>; //# sourceMappingURL=httpClient.types.d.ts.map