Retrieve Weather Forecasts from alitiq-API with Javascript axios and d3 🌤️

Posted . Visible to the public.

Parsing weather forecasts from our Weather API is easy and just needs some lines of code. You need to know which weather forecasting model and the location you want to get forecasts for.

const axios = require('axios');
const d3 = require('d3');

// Configure the request
const weather_model = 'icon_eu'; // without weather_model you will receive mos_mix forecast for the closest location
const response_format = 'json';  // alternative: csv or html
const api_token = ''; // add your token here
const latitude = 49.23247790;
const longitude = 6.98900836;
// const zip_code = 86424;
// const city_name = 'Munich';

// Query API
axios.get(`https://api.alitiq.com/weather_forecast/?latitude=${latitude}&longitude=${longitude}&weather_model=${weather_model}&response_format=${response_format}`, {
    headers: { 'x-api-key': api_token }
})
.then(response => {
    const data = response.data;
    console.log(data);

    // Processing the data using d3
    const parsedData = d3.jsonParse(JSON.stringify(data));
    console.log(parsedData);
})
.catch(error => {
    console.error(error);
});


Further information can be found here Show archive.org snapshot :

Posted by Daniel to alitiq Knowledge (2024-07-01 07:44)