Blog·Craft·

Borders is a real neighbor list

The borders field on /country ships the actual ISO2 codes of countries that share a border.

A neighbor list should have actual neighbors on it.

GET /country/us
{ "country": "us", "name": "United States", "borders": ["CA", "MX"] }

GET /country/br
{ "country": "br", "name": "Brazil", "borders": ["AR", "BO", "CO", "GY", "PY", "PE", "SU", "VE", "UY"] }

borders lists the countries that physically touch this one. Chain each code straight into /country/{code}. ISO2 or ISO3, that route reads either. Each neighbor code is the same shape as a normal country lookup, so one client path covers both.

The list length tells you the shape of the map

The US shows two. Brazil shows nine, one call away from every country on its perimeter. Japan and Australia come back null, there is no length-zero array to loop over because there is no land border to list. Checking for null reads as a plain island check, no separate is_island flag required to ask the same question.

Try it

Call /country/br and loop borders into /country/{code}. Nine neighbors, same shape each time.