saloonphp/saloon
Saloon is a PHP HTTP client framework for building API integrations. Define connectors and requests, handle authentication, retries, and responses, and test easily with fakes and mocking. Works great in Laravel or any PHP app.
Saloon is a highly specialized HTTP client abstraction layer designed to replace ad-hoc Guzzle/cURL implementations with a structured, maintainable SDK framework. It aligns well with Laravel’s ecosystem due to:
psrResponse header handling (v3.15.0) and macroable traits (v3.15.0) integrate seamlessly with Laravel’s service providers and Facades.StripeConnector, ShopifyConnector) that can be registered as Laravel services, promoting SOLID principles and testability.Key Misalignments:
Request, Connector, Response) and testing patterns (e.g., MockClient), which may slow down teams unfamiliar with the package.| Integration Vector | Feasibility | Notes |
|---|---|---|
| Laravel Service Provider | High | Saloon’s Connector classes can be bound as Laravel services with config-driven endpoints. |
| Existing Guzzle Clients | Medium | Requires migration effort to rewrite clients using Saloon’s Request classes. |
| OAuth2/PAT Auth | High | Built-in OAuth2, TokenAuthenticator, and ClientCredentialsGrant (v3.10.0) support. |
| GraphQL/REST Hybrid | Medium | Saloon is REST-focused; GraphQL would need custom middleware or a wrapper. |
| Event-Driven APIs | Low | Not designed for Webhooks/SSE; would require polling or external event handlers. |
| Testing (Pest/PHPUnit) | High | MockClient and fixtures (v3.13.0) simplify API testing. |
Critical Dependencies:
psrResponse in v3.15.0).| Risk Area | Severity | Mitigation |
|---|---|---|
| Security Vulnerabilities | High | Critical fixes in v4.0.0 (CVE-2026-33942, CVE-2026-33182) require immediate upgrade. |
| Breaking Changes | Medium | v4.0.0 introduces foundational improvements (e.g., base URL overrides); test thoroughly. |
| Performance Overhead | Low | Minimal if used correctly; avoid over-fetching or excessive middleware. |
| Vendor Lock-in | Medium | Saloon’s DSL is opinionated; migrating back to Guzzle would require refactoring. |
| Testing Complexity | Low | Fixtures and MockClient reduce flakiness but require setup. |
Key Questions for the Team:
PaymentRequired in v3.10.0) or layer Laravel’s Handler?sendAndRetry in v3.6.4)?Mocker (e.g., for database-backed APIs)?Saloon is optimized for Laravel due to:
Saloon Facade or injected via DI.config/saloon.php.Validator or Form Requests.Non-Laravel Stacks:
| Phase | Actions | Tools/Libraries |
|---|---|---|
| Assessment | Audit existing API clients (Guzzle/cURL/vendor SDKs) for Saloon compatibility. | phpstan, psalm |
| Pilot Project | Migrate 1–2 low-risk APIs (e.g., internal tools, non-critical integrations). | Saloon’s Connector classes, MockClient |
| Core Integration | Replace Guzzle with Saloon’s PSR-18 client in Laravel’s HTTP stack. | symfony/http-client-bundle |
| Auth Refactor | Standardize on Saloon’s Authenticator classes (e.g., BearerToken, OAuth2). |
league/oauth2-client (if needed) |
| Testing Overhaul | Replace HttpTests with Saloon’s fixtures and MockClient. |
PestPHP, PHPUnit |
| Middleware Sync | Port Laravel middleware (e.g., ThrottleRequests) to Saloon’s handler stack. |
Saloon’s Middleware trait |
| Deprecation Cleanup | Remove deprecated methods (e.g., sendAndRetry) and update to v4.0.0. |
roave/security-advisories |
Example Migration:
// Before (Guzzle)
$client = new GuzzleClient();
$response = $client->request('GET', 'https://api.example.com/data', [
'headers' => ['Authorization' => 'Bearer ' . $token],
]);
// After (Saloon)
class GetDataRequest extends Request {
protected Method $method = Method::GET;
protected string $endpoint = 'data';
protected ?string $authToken = null;
public function resolveEndpoint(): string {
return $this->endpoint;
}
public function defaultHeaders(): array {
return ['Authorization' => 'Bearer ' . $this->authToken];
}
}
$connector = new ExampleConnector();
$response = $connector->send(new GetDataRequest(['authToken' => $token]));
| Compatibility Check | Status | Notes |
|---|---|---|
| Laravel 10.x/11.x | ✅ Full | PSR-18/PSR-7 alignment ensures compatibility. |
| PHP 8.1–8.5 | ✅ Full | v3.14.2+ supports PHP 8.5; v4.0.0 may require PHP 8.2+. |
| Guzzle 7.x | ⚠️ Partial | Saloon uses Symfony’s client; Guzzle middleware may need adaptation. |
| OAuth2 Libraries | ✅ Full | Works with league/oauth2-client or Saloon’s built-in ClientCredentialsGrant. |
| GraphQL Clients | ❌ No | Requires custom middleware (e.g., relay-runtime or webonyx/graphql-php). |
| Legacy SOAP/XML-RPC | ⚠️ Partial | Possible with custom middleware |
How can I help you explore Laravel packages today?