Skip to content

Instantly share code, notes, and snippets.

@tomfordrumm
Created February 8, 2025 21:45
Show Gist options
  • Save tomfordrumm/338502cd6f43b4f1c5ee65b2d96b0c76 to your computer and use it in GitHub Desktop.
Save tomfordrumm/338502cd6f43b4f1c5ee65b2d96b0c76 to your computer and use it in GitHub Desktop.
Example of openweathermap.org api call
const lat = 40.7128; // Широта, например, Нью-Йорк
const long = -74.0060; // Долгота, например, Нью-Йорк
const apiKey = 'your_api_key_here'; // Ваш API-ключ
fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&appid=${apiKey}`)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Weather data:', data);
})
.catch(error => {
console.error('Error fetching weather data:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment