Integration examples
MCAPI.TR examples for websites, bots, server plugins and the command line.
HTML / JavaScript
Requirements and usage
Modern browser. Open this file through a local HTTP server.
Official documentation ↗<!doctype html>
<html lang="en"><meta charset="utf-8"><title>Minecraft status</title>
<button id="check">Check server</button><pre id="result" role="status"></pre>
<script>
const address = 'mc.hypixel.net';
document.querySelector('#check').addEventListener('click', async () => {
const button = document.querySelector('#check');
const output = document.querySelector('#result');
button.disabled = true;
try {
const response = await fetch('https://mcapi.tr/api/v1/status/' + encodeURIComponent(address), {
signal: AbortSignal.timeout(20000)
});
if (response.status === 404) { output.textContent = 'Offline or unreachable'; return; }
if (!response.ok) throw new Error('HTTP ' + response.status);
const data = await response.json();
output.textContent = (data.stale ? 'Last known data: ' : '') +
(data.online ? 'Online: ' + (data.players?.online ?? '?') + ' players' : 'Offline');
} catch (error) { output.textContent = 'Check failed: ' + error.message; }
finally { button.disabled = false; }
});
</script></html>Examples handle 404 responses, HTTP failures and stale data. Cache results for at least 60 seconds in your own app; keep bot tokens on your server.