Простой API тестер для отправки GET и POST запросов. Позволяет проверять ответы сервера прямо в браузере.
👁 10
const root = container;
root.innerHTML = `
<div style="font-family:monospace; max-width:700px;">
<h2>API Tester</h2>
<input id="url" placeholder="https://api.example.com" style="width:100%; padding:8px; margin-bottom:8px;">
<select id="method" style="width:100%; padding:8px; margin-bottom:8px;">
<option>GET</option>
<option>POST</option>
</select>
<textarea id="body" placeholder="JSON body (для POST)" style="width:100%; height:100px;"></textarea>
<button id="send">Отправить</button>
<pre id="result" style="margin-top:10px; background:#000; padding:10px;"></pre>
</div>
`;
const url = root.querySelector("#url");
const method = root.querySelector("#method");
const body = root.querySelector("#body");
const result = root.querySelector("#result");
root.querySelector("#send").onclick = async () => {
try {
const res = await fetch(url.value, {
method: method.value,
headers: { "Content-Type": "application/json" },
body: method.value === "POST" ? body.value : null
});
const text = await res.text();
result.textContent = text;
} catch(e){
result.textContent = "Ошибка: " + e.message;
}
};