PHP code example of lsv / windy-php-api

1. Go to this page and download the library: Download lsv/windy-php-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lsv / windy-php-api example snippets




sv\Windy\Request;
use Lsv\Windy\PointForecast\PointForecastRequest;
use Lsv\Windy\PointForecast\WeatherModels\WeatherModels;
use Lsv\Windy\Shared\Point;

// Your Windy API key
$apiKey = 'your_api_key_here';

// Create a new request instance
$request = new Request($apiKey);

// Create a new PointForecastRequest
$forecastRequest = new PointForecastRequest(
    point: new Point(latitude: 55.6761, longitude: 12.5683), // Example coordinates: Copenhagen, Denmark
    model: WeatherModels::AROME, // Multiple weather models are supported eg WeatherModels::IconEU, WeatherModels::GFS
    parameters: null, // Optional: Use default parameters accepted by the model multiple parameters are available eg. [WeatherParameter::temp, WeatherParameter::dewpoint]
    levels: null      // Optional: Use default levels [Levels::surface] is default, multiple levels are supported eg [Levels::surface, Levels::h1000]
);

// Send the request and get the response
try {
    $response = $request->request($forecastRequest);
    // $response is an array of Time[] objects
    // $response[0]->time - DateTimeInterface;
    // $response[0]->values - array of Value[] objects
    // $response[0]->values[0]->name - name of the value;
    // $response[0]->values[0]->unit - string - The value unit
    // $response[0]->values[0]->value - int|float - the value;
} catch (\Throwable $e) {
    echo 'Error: ' . $e->getMessage();
}
bash
composer fix