- How does saloonphp/laravel-plugin compare to Laravel’s built-in HTTP client (Http::) for API integrations?
- The Laravel plugin for Saloon provides a more structured, typed approach compared to Laravel’s Http facade. It enforces connectors (e.g., `StripeConnector`) for API clients, reducing boilerplate and enabling better IDE support, mocking, and middleware integration. Use Saloon for complex APIs (GraphQL, OAuth) or when you need strict typing and testing consistency.
- Can I use saloonphp/laravel-plugin with Laravel 10+ and PHP 8.3+?
- Yes, the package is designed to work with modern Laravel versions and PHP 8.3+. However, ensure compatibility with Saloon v2+ (released 2026), as future updates may introduce breaking changes. Check the package’s changelog for version-specific notes, and test thoroughly during upgrades.
- How do I configure Saloon connectors to work with Laravel’s service container?
- Bind connectors as singletons in your `AppServiceProvider` using `$this->app->bind(Connector::class, fn() => new Connector(config('saloon.api_key')))`. This ensures Saloon instances are resolved via Laravel’s container, enabling dependency injection and testing. Global defaults (timeouts, retries) can also be set in `config/saloon.php`.
- Does saloonphp/laravel-plugin support Laravel’s middleware stack (e.g., Authenticate, ThrottleRequests)?
- Yes, Saloon connectors integrate with Laravel’s middleware via `withMiddleware()` or global extensions using `Saloon::extend()`. For example, add `ThrottleRequests::class` to your connector’s middleware array, or register middleware globally in `app/Http/Kernel.php` for all Saloon requests.
- How can I mock Saloon connectors for unit testing in Laravel?
- Use Saloon’s built-in `MockConnector` to simulate API responses in tests. Replace your connector binding with a mock in `phpunit.xml` or tests: `$this->app->bind(StripeConnector::class, fn() => MockConnector::for(StripeConnector::class))`. This works seamlessly with Laravel’s testing helpers like `actingAs()` or `fake()`.
- Is saloonphp/laravel-plugin suitable for high-volume APIs with async processing?
- Yes, the package integrates with Laravel’s queue system via `Saloon::queue()` or `shouldQueue()`. Dispatch connectors as jobs (e.g., `StripeConnector::dispatchSync()`) to handle background tasks like webhooks or batch syncs. Combine with Laravel’s cache drivers (Redis, file) for rate-limiting or response caching.
- What’s the best way to handle authentication (OAuth, JWT, API keys) with Saloon in Laravel?
- Saloon supports all auth methods via middleware or connector configuration. For OAuth, use `withMiddleware(OAuthMiddleware::class)`; for API keys, pass tokens via `withToken()` or `withHeaders()`. Laravel’s `Auth` facade can also inject tokens dynamically. Custom middleware can integrate with Laravel’s `Auth::user()` for session-based auth.
- Can I use saloonphp/laravel-plugin for GraphQL or SOAP APIs, not just REST?
- Absolutely. Saloon’s connectors are protocol-agnostic, so you can use them for GraphQL (via `GraphQLConnector`) or SOAP (via `SoapConnector`). The Laravel plugin extends this with Laravel’s event system (e.g., `GraphQLRequested`) and middleware support. However, teams new to these protocols may need additional training or documentation review.
- How do I migrate from Laravel’s Http facade to saloonphp/laravel-plugin incrementally?
- Start by replacing one or two high-complexity APIs (e.g., Stripe, GitHub) with Saloon connectors. Replace raw calls like `Http::get()` with `app(Connector::class)->method()`. Use Laravel’s `config/saloon.php` to centralize defaults (timeouts, retries). Gradually standardize naming (e.g., `PascalCaseConnector`) and add middleware globally.
- Are there alternatives to saloonphp/laravel-plugin for typed HTTP clients in Laravel?
- Alternatives include Laravel’s native `Http` facade (simpler but less structured), Spatie’s `laravel-http-client` (for Guzzle), or custom solutions like `GuzzleHttp` with PSR-18. Saloon stands out for its typed connectors, DDD alignment, and built-in testing/mocking. Choose Saloon if you prioritize consistency, observability, and complex API support over minimalism.