ohdearapp/ohdear-php-sdk
Official PHP SDK for the Oh Dear API (built on Saloon v4). Authenticate with an API token, manage monitors, fetch user info, and more with typed DTOs and iterators. Configurable timeouts and clear exceptions for validation and API errors.
CheckResult::isDown()).events system) when monitor states change (e.g., MonitorDown, CertificateExpiring), enabling reactive workflows.OhDear client to the container, enabling dependency injection.OhDear::monitors()) could simplify usage in Blade templates or controllers.requestCheckRun()) can be wrapped in Laravel queues to avoid blocking requests.monitors table).Http::fake()).| Risk Area | Mitigation Strategy |
|---|---|
| API Rate Limits | Implement exponential backoff in retries and monitor API usage via Oh Dear’s rate limit docs. |
| Token Management | Store API tokens in Laravel’s env() or Vault (e.g., Hashicorp Vault). Rotate tokens via Oh Dear’s API. |
| Schema Changes | Use Saloon’s schema validation to catch API contract mismatches early. Monitor Oh Dear’s changelog for breaking changes. |
| Performance | For high-frequency checks (e.g., every minute), cache responses (e.g., Redis) or use Oh Dear’s webhooks instead. |
| Error Handling | Extend Saloon’s exceptions to log structured errors (e.g., Sentry) and implement circuit breakers for transient failures. |
$this->app->singleton(OhDear::class, function ($app) {
return new OhDear(config('services.ohdear.token'));
});
config/services/ohdear.php:
'token' => env('OHDEAR_API_TOKEN'),
'timeout' => env('OHDEAR_TIMEOUT', 10),
CreateMonitorJob).OhDear::dispatchSync(new CreateMonitorJob($monitorData));
MonitorStatusUpdated).public function handle(MonitorStatusUpdated $event) {
if ($event->monitor->isDown()) {
Alert::send('slack', $event->monitor->url);
}
}
Saloon::shouldReceive('get')
->with('monitors')
->andReturn(new OhDearResponse([...]));
OhDearService.requestCheckRun).php artisan ohdear:sync-monitors).| Step | Task | Dependencies |
|---|---|---|
| 1 | Set up SDK in Laravel | Composer, Laravel config |
| 2 | Implement monitor CRUD | Oh Dear API token |
| 3 | Add status page logic | Monitor integration |
| 4 | Queue async operations | Laravel queues |
| 5 | Add caching layer | Redis |
| 6 | Build event listeners | Laravel events |
| 7 | Add webhook endpoints | Oh Dear webhook setup |
composer update ohdearapp/ohdear-php-sdk --with-dependencies.$ohDear->rotateToken(oldToken: 'abc123', newToken: 'def456');
$request = new CreateMonitorRequest(['url' => 'invalid']);
$response = $ohDear->send($request); // Throws ValidationException
$ohDear = new OhDear(token: '...', debug: true);
timeoutInSeconds for slow endpoints.monitors?page=2) for large datasets.How can I help you explore Laravel packages today?