Today what we discuss about the weather API. and I take only few minutes to explain so please to read full post. They first all known the what is API.
API(Application Programming Interface):
- You send a request (request temperature)
2.The API processes it (processing)
3.You get back a response(responding and get the temperature)
They first need a API key, So we open any browser and open weather map and sign in and touch the profile and click the my API keys.and showing key you can copy.

finally we discuss about the code.and the code is
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>weather api</title>
</head>
<body>
<!-- weather api -->
<input id="inp" placeholder="enter city name" type="text">
<button id="ent" onclick="btn()">click</button>
<p id="upt">temperature</p>
<script>
function btn(){
const city=document.getElementById("inp")
const tem=document.getElementById("upt")
const apiKey="0bd88a991b758963b717401bb91dec54"
if(city.value===""){
tem.innerText = "Enter a city";
return
}
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city.value}&appid=${apiKey}&units=metric`)
.then((res)=>{return res.json()})
.then((data)=>{console.log(data)
tem.innerText=data.main.temp
})
.catch((rej)=>{console.log(rej)
tem.innerText="api error"})
city.value=""
}
</script>
</body>
</html>

Top comments (0)