Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/AndresLopezCorrales/Countries-WebPage/llms.txt

Use this file to discover all available pages before exploring further.

The search bar lets users look up any country in the REST Countries database without clicking the map. It accepts English common names (e.g., Germany) and official names (e.g., Federal Republic of Germany). The input is located in the top navigation bar and is always visible, making it the fastest way to reach countries that are hard to click on the map or whose shapes are too small to target.
1

Type the country name

Enter the country name in English into the input field labeled Search for a country in the navigation bar.
2

Submit the search

Click the Buscar button or press Enter to submit the form.
3

View results

The page reloads and the country information panel appears on the right side of the screen (or below the map on mobile), showing the flag, name, capital, population, languages, timezone, and region.

Valid search formats

The table below shows examples of inputs that succeed and inputs that fail, so you can predict how the app will respond.
InputResult
GermanyFederal Republic of Germany ✓
Federal Republic of GermanySame result as above ✓
DeutschlandError — not English or official name ✗
SpainKingdom of Spain ✓
United StatesUnited States of America ✓
japanJapan ✓ (case-insensitive at the API level)

How search works

The search form in index.php uses method="post" with a text field named search and a submit button named submit. When the form is submitted, the PHP backend processes it through the following flow:
  1. ApiConsumer::searchBar() checks for both isset($_POST['submit']) and isset($_POST['search']). If both are set, it returns the value of $_POST['search']; otherwise it returns an empty string.
  2. ApiConsumer::getSearchBarInfo() calls searchBar() first. If a non-empty string is returned, it is used as the country name. If the search bar is empty, the method falls back to GetNameController::clickCountries(), which reads $_POST['titulo'] from a map click.
  3. The country name has its spaces replaced with %20 using str_replace() before being interpolated into the API URL: https://restcountries.com/v3.1/name/{name}.
This means if both a search input and a map click are present in the same POST request, the search bar takes priority.
The search is case-insensitive at the REST Countries API level, but the name must be in English. The popover info button (the ⓘ icon in the navbar) also displays this reminder in both English and Spanish: “The country names are ONLY VALID if they are in the english language or putting their official name.”

Error handling

When the submitted name does not match any country in the REST Countries database, the API returns a JSON error object. Country-Click detects two conditions and renders an error message in both cases:
  • The response JSON contains "status": 404
  • The response JSON contains "message": "Page Not Found"
The PHP check that triggers the error message is:
ApiConsumer.php
if (isset($data["status"]) && $data["status"] === 404 
    || isset($data["message"]) && $data["message"] === "Page Not Found") {
    echo "<p>Doesn't exist. Try with the official name or the english name.</p>";
}
If file_get_contents() returns false (a network failure or unreachable host), the exception is caught and the same error message style is displayed.

Frequently asked questions

The app queries the REST Countries API using English names only. If the common English name fails, try the country’s official name. For example, if Ivory Coast does not return results, try Côte d'Ivoire. The API’s /name/ endpoint performs a partial-match search, so both forms often work — but non-English names (e.g., German, French, or local names) will always return a 404 error.
No. The app queries the REST Countries API exclusively via the /v3.1/name/ endpoint, which matches on country names only. Searching for a capital such as Berlin or Tokyo will return a 404 error because those strings do not match any country name in the database.
Submitting an empty search field causes ApiConsumer::searchBar() to return an empty string. getSearchBarInfo() then checks whether a map click ($_POST['titulo']) is also absent. If both are empty, no API request is made and the info panel remains blank. No error message is shown.

Build docs developers (and LLMs) love