import type { HttpDefine, HttpInjectInfo } from './type' import { http } from './http' export class HTTPClient { base: HttpDefine inject: HttpInjectInfo constructor(base: HttpDefine, inject?: HttpInjectInfo) { this.base = base this.inject = inject || {} } request(config: HttpDefine): Promise { return http({ ...this.base, ...config }, this.inject) } get(url: string, query?: any, config?: HttpDefine): Promise { return this.request({ ...config, url, method: 'get', query }) } delete(url: string, query?: any, config?: HttpDefine): Promise { return this.request({ ...config, url, method: 'delete', query }) } head(url: string, config?: HttpDefine): Promise { return this.request({ ...config, url, method: 'head' }) } options(url: string, config?: HttpDefine): Promise { return this.request({ ...config, url, method: 'options' }) } post(url: string, body?: any, config?: HttpDefine): Promise { return this.request({ ...config, url, method: 'post', body, }) } put(url: string, body?: any, config?: HttpDefine): Promise { return this.request({ ...config, url, method: 'put', body, }) } patch(url: string, body?: any, config?: HttpDefine): Promise { return this.request({ ...config, url, method: 'patch', body, }) } }