> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/igorek05m/daily-geogame/llms.txt
> Use this file to discover all available pages before exploring further.

# GET /api/country

> Fetch country details from RestCountries API with caching

A caching proxy endpoint that retrieves country information from the RestCountries API. This endpoint exists to provide consistent caching behavior for country lookups.

## Endpoint

```http theme={null}
GET /api/country
```

## Query parameters

<ParamField query="code" type="string" required>
  The ISO 3166-1 alpha-2 or alpha-3 country code (e.g., "PL" or "POL").
</ParamField>

## Response

Returns the raw response from RestCountries API v3.1. The response is an array containing country data.

<ResponseField name="[0]" type="object" required>
  Country data object from RestCountries API

  <Expandable title="Country data structure">
    <ResponseField name="name" type="object">
      Contains country name variations including `common` and `official`
    </ResponseField>

    <ResponseField name="cca2" type="string">
      ISO 3166-1 alpha-2 code
    </ResponseField>

    <ResponseField name="cca3" type="string">
      ISO 3166-1 alpha-3 code
    </ResponseField>

    <ResponseField name="latlng" type="number[]">
      Coordinates as `[latitude, longitude]`
    </ResponseField>

    <ResponseField name="borders" type="string[]">
      Array of alpha-3 codes for bordering countries
    </ResponseField>

    <ResponseField name="area" type="number">
      Country area in square kilometers
    </ResponseField>

    <ResponseField name="population" type="number">
      Country population
    </ResponseField>

    <ResponseField name="flags" type="object">
      Contains `svg` and `png` flag URLs
    </ResponseField>

    <ResponseField name="region" type="string">
      Geographic region
    </ResponseField>

    <ResponseField name="subregion" type="string">
      Geographic subregion
    </ResponseField>
  </Expandable>
</ResponseField>

## Caching

This endpoint uses Next.js's `force-cache` strategy:

```typescript theme={null}
const res = await fetch(`https://restcountries.com/v3.1/alpha/${code}`, {
    cache: 'force-cache'
});
```

From `app/api/country/route.ts:11-13`

Country data is cached indefinitely to reduce external API calls and improve performance.

## Example request

```bash theme={null}
curl https://yourdomain.com/api/country?code=PL
```

## Example response

```json theme={null}
[
  {
    "name": {
      "common": "Poland",
      "official": "Republic of Poland",
      "nativeName": {
        "pol": {
          "official": "Rzeczpospolita Polska",
          "common": "Polska"
        }
      }
    },
    "cca2": "PL",
    "cca3": "POL",
    "latlng": [52, 20],
    "borders": ["BLR", "CZE", "DEU", "LTU", "RUS", "SVK", "UKR"],
    "area": 312679,
    "population": 37950802,
    "flags": {
      "png": "https://flagcdn.com/w320/pl.png",
      "svg": "https://flagcdn.com/pl.svg"
    },
    "region": "Europe",
    "subregion": "Central Europe",
    "capital": ["Warsaw"],
    "languages": {
      "pol": "Polish"
    },
    "currencies": {
      "PLN": {
        "name": "Polish złoty",
        "symbol": "zł"
      }
    }
  }
]
```

<Note>
  The response includes many additional fields beyond what's shown above. Refer to the [RestCountries API documentation](https://restcountries.com) for the complete schema.
</Note>

## Error responses

**Missing country code:**

```json theme={null}
{
  "error": "Country code is required"
}
```

Status: `400`

**Failed to fetch from RestCountries:**

```json theme={null}
{
  "error": "Internal Server Error"
}
```

Status: `500`

## Code example

```typescript theme={null}
// Fetch country details by code
const response = await fetch('/api/country?code=PL');
const [countryData] = await response.json();

console.log(countryData.name.common); // "Poland"
console.log(countryData.capital[0]); // "Warsaw"
```

## Use cases

This endpoint is primarily used by:

* Country search/autocomplete components
* Guess validation in the game interface
* Displaying country details after user selection
