{"id":15578353,"url":"https://github.com/benjaminhansen/nws-php","last_synced_at":"2025-12-29T16:21:48.019Z","repository":{"id":233295107,"uuid":"786928572","full_name":"benjaminhansen/nws-php","owner":"benjaminhansen","description":"PHP Library for the National Weather Service REST API","archived":false,"fork":false,"pushed_at":"2024-09-05T01:13:52.000Z","size":62,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-24T21:05:46.464Z","etag":null,"topics":["api-weather-gov","national-weather-service","nws","php","weather-gov","weather-gov-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benjaminhansen.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-15T15:10:44.000Z","updated_at":"2024-12-17T03:04:02.000Z","dependencies_parsed_at":"2024-04-20T18:31:19.206Z","dependency_job_id":"4fb16f0c-bace-4685-91d2-e27cf0250a0a","html_url":"https://github.com/benjaminhansen/nws-php","commit_stats":null,"previous_names":["benjaminhansen/nws-php"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminhansen%2Fnws-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminhansen%2Fnws-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminhansen%2Fnws-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminhansen%2Fnws-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benjaminhansen","download_url":"https://codeload.github.com/benjaminhansen/nws-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242326577,"owners_count":20109398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-weather-gov","national-weather-service","nws","php","weather-gov","weather-gov-api"],"created_at":"2024-10-02T19:09:31.380Z","updated_at":"2025-12-29T16:21:42.987Z","avatar_url":"https://github.com/benjaminhansen.png","language":"PHP","readme":"# PHP Library for the National Weather Service REST API\n\nProvides an intuitive interface to use the NWS REST API (https://api.weather.gov) in any PHP application.\n\nPairs well with my ArcGIS Geocode API wrapper as well.\nhttps://github.com/benjaminhansen/arcgis-geocode\n\n## NWS Documentation\nhttps://www.weather.gov/documentation/services-web-api\n\n## Installation\n```\ncomposer require benjaminhansen/nws-php\n```\n\n## Usage\nNotes\n* Requires PHP 8.2 or greater\n* All requests can be cached locally to reduce outbound requests to the API endpoint\n* All datetime fields are automatically returned as a \u003ccode\u003eCarbon\u003c/code\u003e object\n* Any timezone fields are automatically returned as a PHP \u003ccode\u003eDateTimeZone\u003c/code\u003e object\n* A \u003ccode\u003eraw()\u003c/code\u003e method is available on most calls to print out the raw API data\n\n### Example\n\n```php\n\u003c?php\n\nrequire 'vendor/autoload.php'; // if your app it not already including this\n\nuse BenjaminHansen\\NWS\\Api;\n\n/*\n**  We must provide valid contact information so the National Weather Service\n**  can properly identify our application on their end\n*/\n$app_domain = \"website/url\";\n$app_contact = \"email/phone\";\n$api = new Api($app_domain, $app_contact);\n\n\n/*\n** The cache is opt-in. To cache results locally make sure to enable the cache.\n** Sometimes, you may not want to use the cache at all, so this allows it to be toggled on/off.\n*/\n$api-\u003euseCache();\n// $api-\u003euseCache(lifetime: 3600, driver: 'Files'); // override the default cache lifetime seconds and/or storage driver, if necessary\n\n\n/*\n** You can make sure that the API's status returns OK before allowing any\n** requests to be made. An exception will be thrown if the API status is not OK.\n*/\n$api-\u003eassertOk();\n// $api-\u003eassertOk(message: 'custom exception message can be placed here');\n\n\n/*\n**  We can set a timezone for the entire API callstack.\n**  All datetime objects will be converted to this timezone.\n**\n**  If you pass a string version of a timezone, the method will auto-convert it\n**  to a DateTimeZone object.\n*/\n$timezone = \"America/Chicago\";\n// $timezone = new DateTimeZone(\"America/Chicago\");\n$api-\u003etimezone($timezone);\n/*\n    var_dump($api-\u003etimezone())\n\n    object(DateTimeZone)#18 (2) {\n        [\"timezone_type\"]=\u003e\n        int(3)\n        [\"timezone\"]=\u003e\n        string(15) \"America/Chicago\"\n    }\n*/\n\n\n/*\n**  We can provide lat/lon coordinates for a specific location\n**  Dallas, TX for example\n*/\n$lat = 32.7767;\n$lon = -96.7970;\n$location = $api-\u003epoint($lat, $lon);\n\n\n/*\n**  Get the location's county information\n*/\n$county = $location-\u003ecounty;\necho $county-\u003ename;\necho $county-\u003eid;\necho $county-\u003estate-\u003ename;\necho $county-\u003estate-\u003eabbreviation;\nvar_dump($county-\u003etimezone);\nvar_dump($county-\u003etimezones);\n\n\n/*\n** Get information about the location\n*/\necho $location-\u003eradarStationId;\necho $location-\u003ecity;\nvar_dump($location-\u003estate);\n\n\n/*\n** Get any active alerts for the location and loop through them\n*/\n$alerts = $location-\u003eactiveAlerts-\u003eget();\nforeach($alerts as $alert) {\n    var_dump($alert);\n}\n\n\n/*\n** Get current observations from the nearest observation station to your location\n*/\n$observations = $location-\u003elatestObservations;\n$raw_data = $observations-\u003eraw();\nvar_dump($raw_data);\n\necho $observations-\u003etemperature(show_units: true);\n// echo $observations-\u003etemperature;\necho $observations-\u003edewpoint;\n// other methods are available for the other data points as well\n\n\n/*\n** Get the current forecast for the location\n*/\n$forecast = $location-\u003eforecast;\nvar_dump($forecast-\u003eraw());\nvar_dump($forecast-\u003eperiods-\u003eget());\n\n\n/*\n** Get the current hourly forecast for the location\n*/\n$hourly_forecast = $location-\u003ehourlyForecast;\nvar_dump($hourly_forecast-\u003eraw());\nvar_dump($hourly_forecast-\u003eperiods-\u003eget());\n\n\n/*\n** We can also get a specific forecast office\n** Little Rock, Arkansas for example\n*/\n$office_id = \"LZK\";\n$forecast_office = $api-\u003eforecastOffice($office_id);\necho $forecast_office-\u003ename;\necho $forecast_office-\u003ephone;\necho $forecast_office-\u003eemail;\necho $forecast_office-\u003eaddresss;\nvar_dump($forecast_office-\u003ecounties);\nvar_dump($forecast_office-\u003eforecastZones);\nvar_dump($forecast_office-\u003eobservationStations);\nvar_dump($forecast_office-\u003efireZones);\nvar_dump($forecast_office-\u003eactiveAlerts-\u003eget());\n\n\n/*\n** We can also get a specific observation station\n** Little Rock, Arkansas Airport KLIT for example\n*/\n$station_id = \"KLIT\";\n$observation_station = $api-\u003eobservationStation($station_id);\necho $observation_station-\u003ename;\necho $observation_station-\u003eid;\nvar_dump($observation_station-\u003etimezone);\nvar_dump($observation_station-\u003ecounty);\nvar_dump($observation_station-\u003elatestObservations);\nvar_dump($observation_station-\u003eactiveAlerts-\u003eget());\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminhansen%2Fnws-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenjaminhansen%2Fnws-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminhansen%2Fnws-php/lists"}