IP Geolocation API

IP Geolocation API


Getting started with IPWhois.io API

IPWhois.io is a public API that provides information on a given IP address. This API can be used to gather geolocation data, ISP information, and more. In this blog post, we will explore how to access the IPWhois.io API using JavaScript.

Registering for an API Key

To use the IPWhois.io API, you need to sign up for an API key. The registration process is straightforward, and it only takes a few minutes. You can sign up for a free API key by visiting the IPWhois.io website.

Accessing the API

Once you have your API key, you can start accessing the IPWhois.io API. The API supports both HTTP and HTTPS protocols, and it responds with JSON data. Here’s an example of how to use the IPWhois.io API in JavaScript:

const ip = '8.8.8.8';
const apiKey = 'YOUR_API_KEY';

const url = `https://ipwhois.io/json/${ip}?apiKey=${apiKey}`;

fetch(url)
    .then((response) => response.json())
    .then((data) => console.log(data))
    .catch((error) => console.log(error.message));

In the example above, we use the fetch method to send a GET request to the IPWhois.io API endpoint. We pass the IP address and the API key in the URL, and we use the then method to handle the response data.

Example Response

The IPWhois.io API returns a JSON object that contains various details about the given IP address. Here’s an example response:

{
    "ip": "8.8.8.8",
    "success": true,
    "type": "ipv4",
    "continent": "North America",
    "continent_code": "NA",
    "country": "United States",
    "country_code": "US",
    "region": "Virginia",
    "city": "Ashburn",
    "latitude": 39.04375,
    "longitude": -77.48745,
    "isp": "Google LLC",
    "org": "Google LLC",
    "timezone": "America/New_York",
    "timezone_offset": -4,
    "currency": "USD",
    "currency_code": "USD",
    "currency_symbol": "$",
    "currency_rates": {
        "USD": 1,
        "EUR": 0.842564
    },
    "languages": [
        {
            "code": "en",
            "name": "English"
        }
    ]
}

Conclusion

That’s it! You should now be able to access the IPWhois.io API using JavaScript. This API is a great resource for anyone who needs to get geolocation data and other information about an IP address. If you have any questions or comments, please feel free to leave them below.