/*
ブラウザで実行されるJavaScript
役割:
- ボタンイベントを処理
- Flask APIをfetch
*/
// health API呼び出し
document.querySelector("#btn-health").addEventListener("click", async () => {
const res = await fetch("/api/health");
const json = await res.json();
document.querySelector("#out-health").textContent =
JSON.stringify(json, null, 2);
});
// echo API呼び出し
document.querySelector("#btn-echo").addEventListener("click", async () => {
const res = await fetch("/api/echo", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: "test",
time: new Date().toISOString()
}),
});
const json = await res.json();
document.querySelector("#out-echo").textContent =
JSON.stringify(json, null, 2);
});