export class BaseService { protected apiUrl: string | undefined = import.meta.env.VITE_CONJUREOS_HOST protected baseHeaders: Record = { 'Accept': 'application/json', 'API-Version': '1' } protected jsonHeaders: Record = { 'Content-Type': 'application/json', } public constructor() { } protected async get(path: string, headers?: HeadersInit): Promise { return await (await fetch(this.apiUrl + path, { method: 'GET', headers: { ...headers, ...this.baseHeaders } })).json() as T } protected async post(path: string, body: T, headers?: HeadersInit): Promise { return await fetch(this.apiUrl + path, { method: 'POST', body: JSON.stringify(body) as any, headers: { ...headers, ...this.jsonHeaders, ...this.baseHeaders } }); } protected async postForm(path: string, body: FormData, headers?: HeadersInit): Promise { return await fetch(this.apiUrl + path, { method: 'POST', body: body, headers: { ...headers, ...this.baseHeaders } }); } protected async put(path: string, body: T, headers?: HeadersInit): Promise { return await fetch(this.apiUrl + path, { method: 'PUT', body: JSON.stringify(body), headers: { ...headers, ...this.jsonHeaders, ...this.baseHeaders } }); } protected async delete(path: string, headers?: HeadersInit): Promise { return await fetch(this.apiUrl + path, { method: 'DELETE', headers: { ...headers, ...this.baseHeaders } }); } }