Laravel: API client caching conflict with HTTP middleware
Labels: bug, laravel, middleware
Context: Laravel 11 + HTTP Client middleware (Guzzle handler stack)
Description:
When using the Openapi SDK within a Laravel service, the built-in HTTP client middleware is bypassed. This prevents Laravel's retry() or cache() functionality from being applied to Openapi API calls.
Expected: SDK should expose an option to inject a pre-configured Guzzle client or middleware stack.
Impact: Loses consistency with Laravel's HTTP pipeline and prevents centralized caching of API responses.
Hi 👋
I’ve worked on a solution for this and opened a PR that should address the problem. I hope you like it. If u want any changes let me know.
✅ What’s changed
The SDK now allows injecting a custom HTTP client into the Client constructor.
This means you can pass a pre-configured client (e.g. Guzzle with a middleware stack) instead of relying on the internal cURL implementation.
🔧 Example
use OpenApi\Client;
use GuzzleHttp\Client as GuzzleClient;
$guzzle = new GuzzleClient([
// middleware, retry, caching, etc.
]);
$client = new Client($token, $guzzle);
🎯 Result
Requests are now executed through the provided HTTP client, so any configured middleware (like Laravel retry() or cache()) is preserved.
The default behavior remains unchanged if no custom client is provided.
Great work @Seraphim200001, thanks for the contribution! 🙌 We’re reviewing it and planning to merge it soon 🚀