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

1.1.2 2025-11-24 21:46 UTC

This package is auto-updated.

Last update: 2025-11-24 21:48:12 UTC


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

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.