A random country API for quizzes and test data

Get a random country on every request — full record, flag, capital and more. Perfect for geography quizzes, "country of the day" widgets and seeding test data. Free, no API key.

Back

Geography quizzes, "country of the day" banners, a map game's next prompt, or just realistic seed data for a form — they all need the same thing: one country, picked at random, with real fields on it.

One random country

curl "https://countries.dev/random"
{
  "name": "Lithuania",
  "capital": "Vilnius",
  "region": "Europe",
  "flag": "🇱🇹"
}

It's a normal country record, so every field is there — population, currencies, languages, borders, ISO codes. The response is sent with no-store, so a CDN or browser won't hand you the same country twice.

Just the fields you need

For a quiz prompt you rarely want the whole object. Trim it with fields:

curl "https://countries.dev/random?fields=name,capital,flag"
const { name, capital, flag } = await fetch(
  "https://countries.dev/random?fields=name,capital,flag",
).then((r) => r.json());

question.textContent = `${flag} What is the capital of ${name}?`;
answer = capital; // "Vilnius"

A "country of the day"

If you want the same country for everyone on a given day rather than a true random, pick one deterministically from the full list instead — fetch all countries once and index by day-of-year:

const all = await fetch("https://countries.dev/countries?fields=name,flag")
  .then((r) => r.json());
const dayOfYear = Math.floor((Date.now() / 86400000) % all.length);
const today = all[dayOfYear];

Random docs →

Written by

Dov Azencot

At

Thu Jun 25 2026