Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Ohdear Php Sdk

Ohdear Php Sdk Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Oh Dear PHP SDK is the official PHP client for the Oh Dear monitoring API, built on Saloon v4 for a modern, typed integration. Instantiate OhDear with your API token and interact with resources like monitors via convenient methods that return DTOs and iterators.

Designed for clarity and reliability, it includes sensible defaults (like a 10s timeout) and consistent exception handling so you can integrate monitoring operations into your apps with minimal boilerplate.

  • Official SDK for the Oh Dear API
  • Saloon v4 powered HTTP layer
  • Typed DTOs and iterable collections (e.g., monitors)
  • Configurable timeouts via constructor options
  • Robust error handling with ValidationException and OhDearException
Frequently asked questions about Ohdear Php Sdk
How do I install the Oh Dear PHP SDK in a Laravel project?
Run `composer require ohdearapp/ohdear-php-sdk` in your project directory. The SDK is dependency-free and works with Laravel’s service container. No additional Laravel-specific setup is required unless you want to bind it to the container for dependency injection.
Which Laravel versions does this SDK support?
The SDK itself is framework-agnostic but is designed to work with Laravel 8.x and later. It leverages Saloon v4, which has no Laravel-specific dependencies. Test compatibility with your Laravel version by checking the SDK’s `composer.json` for PHP version requirements.
Can I use this SDK to create and manage Oh Dear monitors programmatically?
Yes. The SDK provides methods like `createMonitor()` and `monitors()` to list, create, and update monitors. You can pass an array of monitor configurations (e.g., URL, type, team ID) to these methods. Refer to the Oh Dear API docs for valid configuration options.
How do I handle API errors or validation failures in the SDK?
The SDK throws `ValidationException` for validation errors, which includes detailed error messages via `getMessage()` or `errors()`. For other API errors, it throws `OhDearException`. Wrap SDK calls in try-catch blocks to handle these gracefully, or extend the exceptions to integrate with Laravel’s error handling (e.g., Sentry).
Is it possible to integrate this SDK with Laravel’s queue system for async operations?
Yes. Wrap SDK calls in Laravel queue jobs (e.g., `CreateMonitorJob`) to avoid blocking requests. Instantiate the `OhDear` client in the job’s constructor or fetch it from the Laravel container. Use `dispatchSync()` or `dispatch()` to queue the job, depending on your needs.
How do I authenticate with multiple Oh Dear API tokens in a Laravel app?
Store tokens in environment variables (e.g., `OHDEAR_TOKEN_1`, `OHDEAR_TOKEN_2`) and dynamically instantiate the `OhDear` client with the desired token. For advanced use cases, bind multiple clients to the Laravel container using different token configurations or use a facade to switch tokens contextually.
Can I cache Oh Dear API responses in Laravel to reduce rate limits or improve performance?
Yes. Cache responses using Laravel’s cache system (e.g., Redis) or Saloon’s built-in caching. For example, cache monitor lists for 5 minutes with `Cache::remember()`. Avoid caching sensitive data like monitor states if you need real-time updates. Monitor Oh Dear’s rate limits to ensure compliance.
Does this SDK support webhooks or real-time updates from Oh Dear?
The SDK itself is synchronous and doesn’t handle webhooks directly. However, you can extend it to listen to Oh Dear’s webhooks (e.g., for monitor status changes) by creating a Laravel route or queue job to process incoming webhook payloads. Combine this with the SDK to fetch additional monitor details as needed.
How do I test my Laravel app’s integration with the Oh Dear SDK?
Use Saloon’s mocking capabilities to simulate API responses in PHPUnit tests. For example, mock `GetMonitorsRequest` to return predefined monitor data: `Saloon::shouldReceive('get')->with('monitors')->andReturn(new OhDearResponse([...]))`. Test error cases by mocking exceptions or HTTP failures.
Are there alternatives to this SDK for integrating Oh Dear with Laravel?
The Oh Dear PHP SDK is the official, maintained solution. Alternatives include using Guzzle directly to call the Oh Dear API or building a custom wrapper around Saloon. However, the official SDK provides DTOs, enums, and validation, reducing boilerplate and ensuring compatibility with Oh Dear’s API changes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport