chaoswd / weather
A lightweight PHP library for interacting with the National Weather Service (weather.gov) API. Provides alerts, daily forecasts, and hourly forecasts using a simple OOP interface.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/chaoswd/weather
Requires
- php: ^8.3
README
A lightweight PHP library for interacting with the National Weather Service (weather.gov) API.
Provides alerts, daily forecasts, and hourly forecasts using a simple OOP interface.
Installation
composer require chaoswd/weather
Usage
use Chaoswd\Weather\Weather; $weather = new Weather( userAgent: 'YourAppName (your-email@example.com)', lat: '47.6062', long: '-122.3321' ); // Get alerts $weather->getAlerts(); print_r($weather->alerts); // Get daily forecast $weather->getDailyForecast(); print_r($weather->daily); // Get hourly forecast $weather->getHourlyForecast(); print_r($weather->hourly); // OR Chain methods $weather->getAlerts()->getDailyForecast()->getHourlyForecast(); print_r($weather->daily);
Finding Your Latitude & Longitude
Use this tool (or any you prefer) to convert a U.S. ZIP code into latitude and longitude:
https://www.freemaptools.com/convert-us-zip-code-to-lat-lng.htm
API Notes
- All requests are sent to https://api.weather.gov
- A proper User-Agent string is required by the NWS API.
Format recommendation:
YourAppName (contact@example.com) - Review their documentation at https://www.weather.gov/documentation/services-web-api
Features
- Fetch active weather alerts
- Fetch full daily forecast
- Fetch hourly forecast
- Auto‑builds required forecast URLs using
/points/{lat},{long}endpoint - Clean, chainable OOP interface
Requirements
- PHP 8.3+
- Composer
- CURL
License
Licensed under the MIT license. See LICENSE for details.