I'm making a web app that uses an API. The problem is that I never did JSON requests with javascript (I used to work with python). Here is my code :
<head>
<title>IP finder pro</title>
<script>
function find_ip() {
var ip = document.getElementById('ip_input').value;
fetch('http://ipapi.co/8.8.8.8/json')
.then(response => response.json())
.then(data => alert(data));
}
</script>
</head>
<body>
<input id="ip_input">
<button id="ip_button" onclick="find_ip()">Click !</button>
</body>
This is the JSON file :
{
"ip": "8.8.8.8",
"city": "Mountain View",
"region": "California",
"region_code": "CA",
"country": "US",
"country_code": "US",
"country_code_iso3": "USA",
"country_capital": "Washington",
"country_tld": ".us",
"country_name": "United States",
"continent_code": "NA",
"in_eu": false,
"postal": "Sign up to access",
"latitude": "Sign up to access",
"longitude": "Sign up to access",
"timezone": "America/Los_Angeles",
"utc_offset": "-0700",
"country_calling_code": "+1",
"currency": "USD",
"currency_name": "Dollar",
"languages": "en-US,es-US,haw,fr",
"country_area": 9629091.0,
"country_population": 310232863.0,
"message": "Please message us at ipapi.co/trial for full access",
"asn": "AS15169",
"org": "GOOGLE"
}
And this is the curl command :
curl 'https://ipapi.co/8.8.8.8/json/'
Do you have any idea of how I could do this?