frontend structiure generated

This commit is contained in:
2025-04-17 17:00:15 +02:00
parent 22b6f3bd2a
commit 3ee632b683
15 changed files with 720 additions and 30 deletions

64
wagfarm-ui/js/api.js Normal file
View File

@@ -0,0 +1,64 @@
// api.js
const API = {
baseUrl: 'https://your-api-url.com/api',
async get(endpoint) {
try {
const response = await fetch(`${this.baseUrl}/${endpoint}`);
if (!response.ok) throw new Error(`API Error: ${response.status}`);
return await response.json();
} catch (error) {
console.error('GET request failed:', error);
throw error;
}
},
async post(endpoint, data) {
try {
const response = await fetch(`${this.baseUrl}/${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (!response.ok) throw new Error(`API Error: ${response.status}`);
return await response.json();
} catch (error) {
console.error('POST request failed:', error);
throw error;
}
},
async put(endpoint, data) {
try {
const response = await fetch(`${this.baseUrl}/${endpoint}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
if (!response.ok) throw new Error(`API Error: ${response.status}`);
return await response.json();
} catch (error) {
console.error('PUT request failed:', error);
throw error;
}
},
async delete(endpoint) {
try {
const response = await fetch(`${this.baseUrl}/${endpoint}`, {
method: 'DELETE'
});
if (!response.ok) throw new Error(`API Error: ${response.status}`);
return await response.json();
} catch (error) {
console.error('DELETE request failed:', error);
throw error;
}
}
};
export default API;