PHP code example of sablesoft / api-openweather

1. Go to this page and download the library: Download sablesoft/api-openweather 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/ */

    

sablesoft / api-openweather example snippets


    
     use SableSoft\OpenWeather\Service;

    $appId = 'your_appid_here';
    $options = [
        'endpount' => 'http://api.openweathermap.org' // already set as default
        'timeout' => 3, // default
        'connect_timeout' => 3 // default
    ];
    
    $service = Service::getInstance($appId, $baseUrl, $options);

    // get weather forecast by city:
    $response = $service->getByCity('Minsk');
    if ($response->isValid()) {
        print_r($response->getData());
    }
    
    // get weather forecast by coordinates:
    $response = $service->get(53.9006, 27.5590);
    if ($response->isValid()) {
        print_r($response->getData());
    }