/** * @file http * @author david wang */ import { Observable } from 'rxjs'; import { HttpConfigType, HttpRequestOptionsType } from "./type"; import { HttpResponseError } from './response'; export declare class HttpClient { /** @private 公共头部 */ private _commonHeader; /** 是否初始化 */ private _inited; /** @private 全局配置项 */ private _config; private _pubsub; /** * @private 判断是否是合法的请求方法 * @param { string } method 方法名 * @return { boolean } true or false */ private _isValidMethod; /** * @private 参数转换 * @param { object } params 要转换的参数 * @return { string } 转换的值 */ private _convertParam; /** * @private 获取请求路径 * @param { string } url 路径 * @param { string } params 参数 * @return { string } url */ private _getUrl; /** * @private 获取header * @param { object } header header * @return { object } header */ private _getHeader; /** * @private 发送请求 * @param { string } method 请求方法 * @param { string } url 请求地址 * @param { HttpRequestOptionType } options 配置 * @return { object } < Observable > */ private _request; /** * 处理json返回数据 * @param { object } json 返回的json值 * @param { object } response response * @param { object } options 当前请求的配置项 * @return { any } 返回object|httpResponseError */ private _handleJsonResponse; /** * 错误返回处理 * @param { any } err 错误对象 * @param { object } options 配置项 * @return { void } */ private _handleResponseError; /** * 初始化 */ init(config?: HttpConfigType): this; /** * 设置公共头 * @param { string } key header key * @param { any } value header value * @return { void } */ setCommonHeader(key: string, value: any): void; /** * 监听 */ listen(handle: (topic: string, err: HttpResponseError, options: HttpRequestOptionsType) => void): Function; /** * @private 发送请求 * @param { string } method 请求方法 * @param { string } url 请求地址 * @param { HttpRequestOptionType } options 配置 * @return { Object } < Observable > */ request(method: string, url: string, options?: HttpRequestOptionsType): Observable<{ result: any; response: any; isSuccess: boolean; }>; /** * post请求 * @param body * @param options */ post(url: string, body?: any, options?: HttpRequestOptionsType): Observable<{ result: any; response: any; isSuccess: boolean; }>; /** * get * @param params * @package options */ get(url: string, params?: any, options?: HttpRequestOptionsType): Observable<{ result: any; response: any; isSuccess: boolean; }>; /** * put * @param params * @package options */ put(url: string, params?: any, options?: HttpRequestOptionsType): Observable<{ result: any; response: any; isSuccess: boolean; }>; /** * delete * @param params * @package options */ delete(url: string, params?: any, options?: HttpRequestOptionsType): Observable<{ result: any; response: any; isSuccess: boolean; }>; } declare const _default: { createClient: () => HttpClient; }; export default _default;