Country API

Beginner's Pick Geocoding / No Auth Required Beginner HTTPS CORS
Free to Use Varies (check documentation)

Overview

Country.is is a simple, free API that detects a visitor's country based on their IP address. It returns a two-letter country code in milliseconds with no authentication required. It is ideal for beginners who need basic IP geolocation without setting up complex libraries.

Beginner Tip

When testing locally, the API will return a loopback or private network result; deploy to a real server to see accurate country detection. You can also pass any IP as a query parameter: http://country.is/8.8.8.8.

Available Data

country name and code
population
capital city
region and subregion
flag image URL
IP address information

Example Response

JSON Response
{
  "name": "Japan",
  "capital": "Tokyo",
  "population": 125800000,
  "region": "Asia",
  "languages": [
    "Japanese"
  ],
  "flag": "https://flagcdn.com/jp.svg",
  "currencies": [
    {
      "code": "JPY",
      "name": "Japanese yen"
    }
  ]
}

Field Reference

ip The IP address that was queried, either from the caller or the one specified in the URL path.
country Two-letter ISO 3166-1 alpha-2 country code (e.g., "US", "DE", "JP") corresponding to the IP address.

Implementation Example

Request
const url = "http://country.is/";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

Common Errors & Troubleshooting

Returns "ZZ" or empty country code The IP address is private, reserved, or not in the geolocation database.
Use a real public IP address. Local development will always return a private IP; test with a specific IP like /8.8.8.8.
CORS error in browser Some browser security policies block requests to HTTP (non-HTTPS) endpoints.
Make the request from your server-side code rather than directly from the browser, or use a proxy.
Incorrect country detected IP geolocation databases are not 100% accurate, especially for VPNs and proxies.
This is expected behavior. For critical use cases, use a more accurate paid geolocation service.

Metadata Score Breakdown

Estimated from metadata — endpoint not independently tested

This score is estimated from observable metadata — HTTPS support, authentication model, declared CORS, and documentation reachability — because the API requires authentication or exposes no publicly testable endpoint. The five-signal breakdown is only shown for live-tested APIs.

Metadata estimate · endpoint not independently tested

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS YES
Category Geocoding
Difficulty Beginner
Verified: 2026-04-04

Related Tags

Similar APIs

View All →