Files
PIbd-23_Baryshev_D.A._Inter…/js/ApiService.js
Baryshev Dmitry 0ead01438a ты думаешь у меня есть только вера?
болван, мне больше ничего и не надо
2025-05-24 00:38:16 +04:00

41 lines
1.1 KiB
JavaScript

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');