sdk-generator / nager-date-sdk
Unofficial PHP SDK for the Nager.Date Community API (V4): public holidays of more than 200 countries, next holidays, country information and available countries. No API key.
Requires
- php: ^8.4
- sdk-generator/sdk-runtime: ^1.15.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
- dmorenof/nager-date-sdk: v0.1.2
This package is auto-updated.
Last update: 2026-12-03 22:17:26 UTC
README
Public holidays of 200+ countries as typed PHP, no API key.
Public holidays by country and year, the next holidays of a country, country information with its borders and the list of available countries from the Nager.Date Community API, with typed answers and no key to manage.
Unofficial. Not affiliated with, endorsed by or supported by Nager Software Solutions. See NOTICE.md.
Why this SDK
- Free Community API without a key: install and call.
- Run against the live service: the calls in the quick start were made for real.
- Holidays are typed models (date, name, national or regional, types as an enum).
- Generated from the contract, never edited by hand.
src/is produced fromcontract/nager-date.jsonby sdk-generator on top of the shared sdk-runtime: when the contract changes you regenerate, you do not patch. - Typed end to end. 6 operations and 8 typed request, answer and model classes. A request is a model whose fields are checked where you assign them (PHP 8.4 property hooks); an answer is a model; a list is a typed collection. PHPStan at the maximum level reports no error on the whole SDK.
- One way to fail. An HTTP answer the contract does not declare as success is an
ApiExceptionthat keeps the raw response and, when the API documents it, the decoded error as a model. Network failures keep their own type. - Production controls included. PSR-18 HTTP client (Guzzle by default), timeouts (30 s / 10 s by default), retries with
Retry-After, redirect policy, middleware and per-environment servers, all in oneConfigurationobject.
Install
PHP 8.4 or later.
composer require sdk-generator/nager-date-sdk
Quick start
<?php use NagerDateSDK\Api\V4\Holidays\ByCountryCode; use NagerDateSDK\Configuration; use NagerDateSDK\NagerDateAPISDK; use NagerDateSDK\PathParams\Api\V4\Holidays\ByCountryCode\ByYear; $configuration = new Configuration(); NagerDateAPISDK::configure($configuration); $year = new ByYear(); $year->countryCode = 'ES'; $year->year = 2026; foreach (ByCountryCode::getByYear($year) as $holiday) { echo $holiday->date, ' ', $holiday->name, "\n"; }
The same example is in examples/quickstart.php. Every operation is listed in docs/OPERATIONS.md.
What it covers
6 operations. The biggest areas:
| Area | Operations |
|---|---|
api |
6 |
Handling errors
use Dmorenof\SdkRuntime\ApiException; try { // ... any call from the quick start } catch (ApiException $e) { echo $e->response->status, "\n"; // the HTTP status echo $e->response->body, "\n"; // the raw body, always kept var_dump($e->error); // the decoded error model, when the API documents one }
Configuration
Configuration is the only place to set anything: baseUrl, securityCredentials, headers, timeout, connectTimeout, retryPolicy, redirectPolicy, middleware, httpClient (any PSR-18 client), serverVariables. Use Client::connect($configuration) instead of the static facades when you need several independent connections.
Good to know
- Only the Community API V4 is covered; the deprecated V3 and the Pro API (API key) are not.
- Holiday data is informational: check it against official sources when it matters.
- The public service has its own terms of use: https://date.nager.at/Legal/TermsOfService
- Version
0.1.0is a first release: the API of the SDK follows the contract, and a regenerated contract can rename classes. Pin a version. - The SDK has been checked against its contract (generation, static analysis, serialization of requests); it has not been run against the live service unless the section above says so. Use test credentials first.
Documentation
- Operations catalog
- Vendor documentation
- sdk-runtime (what every SDK shares) and sdk-generator
- CHANGELOG.md, CONTRIBUTING.md, SECURITY.md
License
MIT, see LICENSE.md. The license covers this SDK's code, not the API, its trademarks or its terms: see NOTICE.md.