- How do I quickly set up Saloon in a Laravel project?
- Run `composer require saloonphp/laravel-plugin` and execute `php artisan saloon:install`. This publishes the config file, registers the service provider, and sets up basic Laravel integration. No manual configuration is needed for simple use cases.
- Does this package work with Laravel 10 or older versions?
- The package officially supports Laravel 11–13. For Laravel 10, use version 3.x of the plugin, which maintains compatibility. Older versions are not supported due to breaking changes in Laravel’s core. Check the [release notes](https://github.com/saloonphp/laravel-plugin/releases) for version-specific details.
- Can I use Saloon for dynamic API endpoints where contracts aren’t practical?
- Saloon’s contract-first approach works best for structured APIs. For dynamic endpoints, you can still use Saloon’s `Request` classes with runtime parameters or bypass contracts entirely by leveraging its raw HTTP capabilities. However, this reduces some of Saloon’s built-in benefits like validation and mocking.
- How does Saloon integrate with Laravel’s Pulse or Telescope?
- The plugin includes built-in support for Pulse (monitoring API calls) and Telescope (debugging requests/responses). Enable them via the `config/saloon.php` file. Pulse logs API metrics, while Telescope provides detailed request/response inspection, making it easier to debug API issues in production.
- What’s the best way to organize API clients in a large Laravel app?
- Use Saloon’s modular design by placing connectors and requests in subdirectories like `app/Integrations/Stripe/`. Each connector can be bound to the service container individually, allowing for easy dependency injection and testing. This approach keeps your codebase clean and scalable.
- Will Saloon work with custom Laravel middleware (e.g., for auth or logging)?
- Yes, Saloon supports custom middleware via its `Nightwatch` feature. You can extend or replace the default middleware stack in your connector’s configuration. For example, add `->withMiddleware(MyCustomMiddleware::class)` to your connector definition to integrate seamlessly with your app’s middleware.
- How do I mock API responses for testing in Laravel?
- Saloon provides a `MockConnector` class for testing. Define mock responses in your tests using `Saloon::mock()` or `Connector::mock()`. This works alongside Laravel’s testing tools like HTTP tests or Pest, allowing you to simulate API failures, delays, or success responses without hitting real endpoints.
- What’s the performance impact of using Saloon vs. raw Guzzle?
- Saloon adds minimal overhead compared to Guzzle, as it leverages Guzzle under the hood. The primary performance cost comes from contract validation and middleware execution, which are optional. Benchmarks show Saloon’s abstractions introduce <5% latency for most use cases, making it suitable for high-traffic APIs.
- Can I migrate an existing Guzzle-based API client to Saloon incrementally?
- Yes, use feature flags or Laravel’s `shouldUseSaloon()` logic to toggle between old and new implementations. Start by wrapping Guzzle calls in Saloon’s `Request` classes, then gradually replace them. The plugin’s `saloon:connector` Artisan command can scaffold new connectors to ease the transition.
- How does Saloon handle retries and rate limiting in production?
- Saloon includes built-in retry logic with exponential backoff and rate limiting support. Configure these in your connector’s `withRetry()` or `withRateLimiter()` methods. For production, pair this with Laravel’s queue system to avoid blocking requests during retries, ensuring resilience without impacting user experience.