UNPKG

@typed/http

Version:

HTTP requests for node and browsers

30 lines 1.26 kB
import { Disposable } from '@typed/disposable'; import { Effects } from '@typed/effects'; import { Either } from '@typed/either'; export declare type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS' | 'PATCH' | 'HEAD'; export declare type HttpHeaders = Readonly<Record<string, string | undefined>>; export declare type HttpOptions = { readonly method?: HttpMethod; readonly headers?: HttpHeaders; readonly body?: string; }; export declare type HttpResponse<A = unknown> = { readonly responseText: string; readonly status: number; readonly statusText: string; readonly headers: HttpHeaders; }; export interface HttpRequest<A = unknown> extends Effects<HttpEnv, Either<Error, HttpResponse<A>>> { } export declare type HttpCallbacks = { readonly success: (response: HttpResponse) => Disposable; readonly failure: (error: Error) => Disposable; }; export interface HttpEnv { readonly http: (url: string, options: HttpOptions, callbacks: HttpCallbacks) => Disposable; } export interface TestHttpEnv extends HttpEnv { readonly getResponses: () => ReadonlyArray<Either<Error, HttpResponse>>; } export declare type HttpRequestValue<A> = A extends HttpRequest<infer R> ? R : never; //# sourceMappingURL=types.d.ts.map