add another test POST api
This commit is contained in:
parent
abae53cb96
commit
686e395fcd
2 changed files with 41 additions and 1 deletions
|
@ -51,6 +51,13 @@
|
||||||
.btn-post:hover {
|
.btn-post:hover {
|
||||||
background-color: #1976D2;
|
background-color: #1976D2;
|
||||||
}
|
}
|
||||||
|
.btn-coordinates {
|
||||||
|
background-color: #FF9800;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.btn-coordinates:hover {
|
||||||
|
background-color: #F57C00;
|
||||||
|
}
|
||||||
.result {
|
.result {
|
||||||
background-color: #f9f9f9;
|
background-color: #f9f9f9;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
|
@ -86,6 +93,7 @@
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<button class="btn-get" onclick="getData()">📥 GET Data</button>
|
<button class="btn-get" onclick="getData()">📥 GET Data</button>
|
||||||
<button class="btn-post" onclick="createData()">📤 POST Data</button>
|
<button class="btn-post" onclick="createData()">📤 POST Data</button>
|
||||||
|
<button class="btn-coordinates" onclick="createCoordinates()">📍 POST Coordinates</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="status"></div>
|
<div id="status"></div>
|
||||||
|
|
|
@ -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
|
// Funzione per mostrare messaggi di status
|
||||||
function showStatus(message, isSuccess = true) {
|
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
|
// Test di connessione all'avvio
|
||||||
window.addEventListener('load', async () => {
|
window.addEventListener('load', async () => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue