add another test POST api

This commit is contained in:
Alessio Prato 2025-08-02 01:48:18 +02:00
parent abae53cb96
commit 686e395fcd
2 changed files with 41 additions and 1 deletions

View file

@ -51,6 +51,13 @@
.btn-post:hover {
background-color: #1976D2;
}
.btn-coordinates {
background-color: #FF9800;
color: white;
}
.btn-coordinates:hover {
background-color: #F57C00;
}
.result {
background-color: #f9f9f9;
border: 1px solid #ddd;
@ -86,6 +93,7 @@
<div class="button-group">
<button class="btn-get" onclick="getData()">📥 GET Data</button>
<button class="btn-post" onclick="createData()">📤 POST Data</button>
<button class="btn-coordinates" onclick="createCoordinates()">📍 POST Coordinates</button>
</div>
<div id="status"></div>

View file

@ -1,4 +1,4 @@
const API_BASE_URL = 'http://localhost:8000';
const API_BASE_URL = 'https://fbbb261497e3.ngrok-free.app';
// Funzione per mostrare messaggi di status
function showStatus(message, isSuccess = true) {
@ -61,6 +61,38 @@ async function createData() {
}
}
// POST: Inserisce coordinate nel database
async function createCoordinates() {
try {
console.log('📍 Richiesta POST coordinate in corso...');
showStatus('📍 Richiesta POST coordinate in corso...', true);
coordinates = {
"coords": [123.12,456.78],
}
const response = await fetch(`${API_BASE_URL}/geo-access`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(coordinates)
});
const data = await response.json();
if (response.ok) {
showStatus('✅ Coordinate inserite con successo!', true);
showResult(data);
} else {
showStatus(`❌ Errore: ${data.detail || 'Errore sconosciuto'}`, false);
}
} catch (error) {
console.error('Errore POST coordinate:', error);
showStatus(`❌ Errore di connessione: ${error.message}`, false);
}
}
// Test di connessione all'avvio
window.addEventListener('load', async () => {
try {