Files
TD_Portfolio/Weather_Project/assets/js/api.js
T
Tomas Dvorak 882f91ebf6 first commit
2025-01-04 11:45:15 +01:00

30 lines
884 B
JavaScript

'use strict';
const api_key = "e7704bc895b4a8d2dfd4a29d404285b6";
export const fetchData = function (URL, callback) {
fetch(`${URL}&appid=${api_key}`)
.then(res => res.json())
.then(data => callback(data));
}
export const url = {
currentWeather(lat, lon) {
return `https://api.openweathermap.org/data/2.5/weather?${lat}&${lon}&units=metric`
},
forecast(lat, lon) {
return `https://api.openweathermap.org/data/2.5/forecast?${lat}&${lon}&units=metric`
},
airPollution(lat, lon) {
return `https://api.openweathermap.org/data/2.5/air_pollution?${lat}&${lon}`
},
reverseGeo(lat, lon) {
return `https://api.openweathermap.org/geo/1.0/reverse?${lat}&${lon}&limit=5`
},
/**
* @param {string} query Search query e.g.: "London", "New York"
*/
geo(query) {
return `https://api.openweathermap.org/geo/1.0/direct?q=${query}&limit=5`
}
}