import type {FetchOptions} from 'ofetch'; export default class Client { options?: FetchOptions; baseUrl: string; constructor(baseUrl: string, options?: FetchOptions) { this.options = options; this.baseUrl = baseUrl; } async raw(url: string, method: 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'get' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace') { try { const response = await $fetch.raw(`${this.baseUrl}${url}`, { // ...options, ...this.options, method }) return response; } catch (err) { return Promise.reject(err); } } async post(ur: string, options?: FetchOptions,) { try { const response = await $fetch.raw(`${this.baseUrl}${ur}`, { ...options, ...this.options, method: 'POST' }) return response; } catch (err) { return Promise.reject(err); } } async get(ur: string, options?: FetchOptions,) { try { const response = await $fetch.raw(`${this.baseUrl}${ur}`, { ...options, ...this.options, method: 'GET' }) return response; } catch (err) { return Promise.reject(err); } } async put(ur: string, options?: FetchOptions,) { try { const response = await $fetch.raw(`${this.baseUrl}${ur}`, { ...options, ...this.options, method: 'PUT' }) return response; } catch (err) { return Promise.reject(err); } } async del(ur: string, options?: FetchOptions,) { try { const response = await $fetch.raw(`${this.baseUrl}${ur}`, { ...options, ...this.options, method: 'DELETE' }) return response; } catch (err) { return Promise.reject(err); } } }