DEV Community

Daniel Igel
Daniel Igel

Posted on

IP Geolocation in your app without a local database: free REST API with MaxMind GeoLite2

IP geolocation usually means picking a provider, signing up, and either shipping a 60 MB binary inside your app or adding another third-party dependency. For most use cases that's more than you need.

One GET returns country, region, city, timezone, ISP, and ASN for any IPv4 or IPv6 address:

curl --request GET \
  --url 'https://ip-geolocation-api20.p.rapidapi.com/api/v1/geo?ip=8.8.8.8' \
  --header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
  --header 'x-rapidapi-host: ip-geolocation-api20.p.rapidapi.com'
Enter fullscreen mode Exit fullscreen mode

You get country, countryCode, region, city, latitude, longitude, timezone, isp, and as. Primary lookups run against a locally hosted MaxMind GeoLite2 database — no external roundtrip. ip-api.com steps in as automatic fallback when the local DB is unavailable.

Need to geolocate the calling client without reading the IP on the frontend? GET /api/v1/geo/me reads X-Forwarded-For and X-Real-IP headers set by the proxy and returns the same payload — handy for server-side middleware or edge functions.

For enriching a list at once, the batch endpoint resolves up to 50 IPs in a single request with concurrent processing:

const res = await fetch(
  'https://ip-geolocation-api20.p.rapidapi.com/api/v1/geo/batch',
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-rapidapi-key': process.env.RAPIDAPI_KEY,
      'x-rapidapi-host': 'ip-geolocation-api20.p.rapidapi.com',
    },
    body: JSON.stringify({ ips: ['8.8.8.8', '1.1.1.1'] }),
  }
);
const { count, results } = await res.json();
Enter fullscreen mode Exit fullscreen mode

No local database to maintain, no separate GeoIP provider account.

Free tier on RapidAPI: https://rapidapi.com/danieligel/api/ip-geolocation-api20

What do you use today for IP geolocation in production — self-hosted MaxMind, a third-party API, or something else?

Top comments (0)