openapi-php-sdk icon indicating copy to clipboard operation
openapi-php-sdk copied to clipboard

Laravel: API client caching conflict with HTTP middleware

Open francescobianco opened this issue 1 year ago • 2 comments

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.

francescobianco avatar Nov 09 '25 16:11 francescobianco

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.

Seraphim200001 avatar Mar 28 '26 12:03 Seraphim200001

Great work @Seraphim200001, thanks for the contribution! 🙌 We’re reviewing it and planning to merge it soon 🚀

francescobianco avatar Mar 30 '26 14:03 francescobianco