Check Minecraft status with TypeScript
Copy this example, set an optional MINECRAFTSTATUS_API_KEY in the environment, and pass an edition plus address. The example preserves pending, quota and freshness boundaries.
Source
export {};
type StatusBody = { freshness?: "fresh" | "stale" | "missing"; pollUrl?: string; error?: { message?: string }; [key: string]: unknown };
const baseUrl = process.env.MINECRAFTSTATUS_API_BASE ?? "https://minecraftstatus.com";
const edition = (process.argv[2] ?? "java") as "java" | "bedrock";
const address = process.argv[3] ?? "play.example.net";
const headers: Record<string, string> = { accept: "application/json" };
if (process.env.MINECRAFTSTATUS_API_KEY) headers.authorization = `Bearer ${process.env.MINECRAFTSTATUS_API_KEY}`;
const response = await fetch(`${baseUrl}/api/v1/status/${edition}?address=${encodeURIComponent(address)}`, { headers });
const body = await response.json() as StatusBody;
if (response.status === 429) {
throw new Error(`Rate limited; retry after ${response.headers.get("retry-after")} seconds.`);
}
if (response.status === 202) {
console.log(`Pending job: ${body.pollUrl ?? "missing poll URL"}`);
} else if (!response.ok) {
throw new Error(`MinecraftStatus API HTTP ${response.status}: ${body.error?.message ?? "request failed"}`);
} else {
console.log(JSON.stringify(body, null, 2));
if (body.freshness !== "fresh") console.warn(`Freshness is ${body.freshness ?? "unknown"}; do not present it as current.`);
}
Run with an address argument such as java play.example.net. The source files are versioned alongside this documentation under examples/api/typescript/status.typescript.
Choose another language
Contract boundary
Every example branches on HTTP status first, prints a queued job receipt for 202, respects Retry-After for 429, and refuses to present stale or missing freshness as current.