class ApiService { constructor(baseUrl) { this.baseUrl = baseUrl; } async get(endpoint) { const response = await fetch(`${this.baseUrl}/${endpoint}`); return response.json(); } async post(endpoint, data) { const response = await fetch(`${this.baseUrl}/${endpoint}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }); return response.json(); } async put(endpoint, id, data) { const response = await fetch(`${this.baseUrl}/${endpoint}/${id}`, { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }); return response.json(); } async delete(endpoint, id) { const response = await fetch(`${this.baseUrl}/${endpoint}/${id}`, { method: "DELETE", }); return response.json(); } } export const apiService = new ApiService('http://localhost:3000');