saloonphp/laravel-plugin
Laravel plugin for Saloon that adds first-class Laravel integration: config publishing, service provider bindings, facades, Artisan tooling, and convenient client setup. Makes using Saloon HTTP connectors and requests feel native inside Laravel apps.
app/Http/Middleware/). Supports Laravel’s event system (e.g., HttpClientRequested) for observability.StripeConnector, GitHubConnector), mapping to Laravel’s repositories or services layer. Aligns with hexagonal architecture principles.MockConnector) simplifies unit/integration testing, critical for Laravel’s test-driven workflows.config/app.php for HTTP client defaults.Authenticate, ThrottleRequests) via Saloon’s withMiddleware() or global Saloon::extend().shouldQueue() and Laravel’s Bus/Jobs integrate seamlessly for async requests (e.g., webhooks, background syncs).cache() decorator or Saloon::cache().Saloon::debug()) or Laravel’s tap().$this->app->bind(StripeConnector::class, fn() => new StripeConnector())).config/saloon.php for global defaults (timeouts, retries).Saloon\Events\RequestSent/ResponseReceived for cross-cutting concerns.Http::get() calls with typed connectors (e.g., StripeConnector::fetchUser()).Http::fake() with MockConnector for isolated tests.Bus for async requests (e.g., Saloon::queue()).Http calls with Connector::call() in services/controllers.// Before
$user = Http::withToken($apiKey)->get('https://api.stripe.com/v1/users')->json();
// After
$user = app(StripeConnector::class)->fetchUser();
SaloonService trait for Laravel services.PascalCaseConnector).app/Http/Kernel.php for global headers/auth.curl, json, and mbstring (standard in Laravel).guzzlehttp/guzzle) in the same project.composer require saloonphp/laravel-plugin.php artisan vendor:publish --tag=saloon-config.app/Saloon/Connectors/ (or Modules/ if using Luminary).namespace App\Saloon\Connectors;
use Saloon\Connector;
use Saloon\Traits\Pluck;
class StripeConnector extends Connector {
use Pluck;
protected string $baseUrl = 'https://api.stripe.com/v1';
protected string $token = 'sk_live_...';
}
$this->mock(StripeConnector::class, [
'fetchUser' => ['id' => 'user_123']
]);
AppServiceProvider:
$this->app->bind(StripeConnector::class, fn() => new StripeConnector());
config/saloon.php for global settings.ConnectorResponse) integrate with Laravel’s IDE autocompletion.config/saloon.php.debug() method logs requests/responses to Laravel’s log channel.Saloon::extend() to add custom debug middleware.SaloonHttpException; catch and map to Laravel’s HttpResponseException.try {
$response = $connector->call();
} catch (SaloonHttpException $e) {
throw new HttpResponseException($e->getResponse());
}
cache() decorator or Laravel’s cache drivers to reduce API calls.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| API Rate Limiting | 429 responses |
Use Saloon’s retryWhen() decorator with exponential backoff. |
| Connector Misconfiguration | Silent failures | Validate connectors in tests; use Saloon::validate() for schema checks. |
| Queue Worker Failures | Async requests timeout | Implement dead-letter |
How can I help you explore Laravel packages today?