GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - programmatordev/openweathermap-php-api: A fluent PHP client for OpenWeather APIs, including weather, air pollution, geocoding, maps, stations, and One Call

BranchesTags
Open more actions menu

Latest commit

 

History

437 Commits
437 Commits

Folders and files

NameName
Last commit message
Last commit date
.ddev
.ddev
 
 
.github/workflows
.github/workflows
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
AGENTS.md
AGENTS.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
UPGRADE-4.0.md
UPGRADE-4.0.md
 
 
composer.json
composer.json
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

OpenWeatherMap PHP API

Latest Version Software License Tests

A fluent PHP client for OpenWeather APIs covering current and forecast weather, air pollution, geocoding, maps, stations, and One Call. Responses use typed entities that safely handle conditional, missing, and null data.

The library is built on programmatordev/php-api-sdk, which provides HTTP client discovery and optional caching, logging, plugins, and request hooks.

Requirements

  • PHP 8.1 or higher
  • An OpenWeather API key

Installation

Install the library with Composer:

composer require programmatordev/openweathermap-php-api

Getting Started

Create the API client with an OpenWeather API key, then choose an API and call one of its methods:

use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;

$api = new OpenWeatherMap($_ENV['OPENWEATHERMAP_API_KEY']);

$current = $api->weather()->current(
    latitude: 38.7223,
    longitude: -9.1393,
);

echo $current->temperature();
echo $current->temperatureWithUnit();

Response properties may be missing or null, so getters return nullable values where appropriate. Collection getters return empty arrays when the response does not contain that collection.

Configuration

The client defaults to metric units and English. The equivalent explicit configuration is:

use ProgrammatorDev\OpenWeatherMap\Enum\Language;
use ProgrammatorDev\OpenWeatherMap\Enum\Units;
use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap;

$api = new OpenWeatherMap(
    apiKey: $_ENV['OPENWEATHERMAP_API_KEY'],
    options: [
        'units' => Units::METRIC,
        'language' => Language::ENGLISH,
    ],
);

Weather and One Call requests can override those values for one fluent request chain. The client-wide configuration remains unchanged for later requests:

$current = $api
    ->weather()
    ->withUnits(Units::IMPERIAL)
    ->withLanguage(Language::PORTUGUESE)
    ->current(latitude: 38.7223, longitude: -9.1393);

withLanguage() also accepts a non-empty language-code string, allowing new OpenWeather languages to be used without waiting for an enum update.

See OpenWeather's units of measurement and multilingual support documentation for the currently supported values.

Documentation

APIs

These guides cover each API's endpoints, response entities, and usage examples:

  • One Call 4.0
  • Air Pollution
  • Weather
  • Maps
  • Stations
  • Geocoding

Client Guides

These guides cover client configuration and failures shared across the APIs:

  • Setup — Configure caching, logging, HTTP clients, plugins, and request hooks.
  • Error Handling — Handle OpenWeather API errors and client failures.

Upgrading

Version 4 is a complete rewrite without backward compatibility. Existing integrations should treat it as a new implementation. See Upgrading To 4.0 for the release expectations and current baseline.

License

This project is licensed under the MIT License.

About

A fluent PHP client for OpenWeather APIs, including weather, air pollution, geocoding, maps, stations, and One Call

Topics

air-pollutionair-qualityapiforecastgeocodingopenweatheropenweathermapphpphp8psr-17psr-18psr-3psr-6sdkweatherweather-api

Resources

Readme
MIT license
Activity
Custom properties

Stars

3 stars

Watchers

0 watching

Forks

1 fork
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.