guzzlehttp/guzzle
Guzzle is a PHP HTTP client for sending sync or async requests with an easy API. Built on PSR-7 and PSR-18, supports middleware, cookies, streaming uploads/downloads, and JSON. Transport-agnostic for flexible integrations.
HttpClient facade, symfony/http-client). The updated guzzlehttp/psr7 constraint (^2.12.5) aligns with Laravel’s PSR-7 implementation (e.g., nyholm/psr7:^1.6 in Laravel 10+).GuzzleHttp\Middleware::tap() for observability alongside Laravel’s middleware.stream => true with capped handlers), reducing edge-case failures in Laravel’s file downloads.CURLOPT_HTTPAUTH + NTLM) may require updates to custom HttpClient wrappers using low-level cURL options.// Safe proxy configuration in Laravel's HttpClient
$client = new \GuzzleHttp\Client([
'proxy' => 'http://user:[email protected]',
'handler' => \GuzzleHttp\HandlerStack::create(
\GuzzleHttp\Middleware::retry(new \GuzzleHttp\RetryMiddleware(), [
'max_retries' => 3,
])
),
]);
$this->app->bind(\GuzzleHttp\Client::class, fn () => new \GuzzleHttp\Client(config('guzzle.defaults')));
sendAsync() for non-blocking calls:
$promise = $client->getAsync('https://api.example.com/webhook');
$promise->then(fn ($response) => Queue::dispatch(new ProcessWebhook($response)));
CURLOPT_HTTPAUTH) may fail if combined with proxies. Mitigation:
config/guzzle.php for raw cURL options.GuzzleHttp\Middleware::auth).stream => true with capped handlers. Risk: Laravel’s file downloads (e.g., Http::download()) may fail if using custom stream handlers. Mitigation:
on_trailers callback is now validated earlier, which may affect custom middleware. Mitigation: Update middleware to handle trailer validation:
$client->get('...', [
'on_trailers' => fn (array $trailers) => logger()->info('Trailers', $trailers),
]);
stream => true with custom stream handlers? Verify compatibility with 7.14.1’s restrictions.on_trailers or raw cURL options? Update middleware to comply with 7.14.1’s validation.HttpClient facade without changes. Use the facade’s custom macro to override defaults:
Http::macro('secure', fn () => new \GuzzleHttp\Client([
'timeout' => 30,
'headers' => ['User-Agent' => 'Laravel/10'],
]));
$promise = Http::secure()->getAsync('https://api.example.com/data');
$promise->then(fn ($response) => Queue::push(new ProcessData($response->getBody())));
use GuzzleHttp\Middleware;
$stack = Middleware::tap(fn ($request, $next) => logger()->info('Request', $request));
$client = new \GuzzleHttp\Client(['handler' => HandlerStack::create($stack)]);
php-http/client-implementation) and Laravel packages like spatie/laravel-activitylog (for HTTP event logging).curl (≥7.34.0) or openssl for HTTPS. Guzzle 7.14.1 defaults to cURL if available, with fallback to streams.CURLOPT_HTTPAUTH).stream => true.composer require guzzlehttp/guzzle:^7.14 --update-with-dependencies
composer remove illuminate/http-guzzle # If using Laravel's bundled Guzzle 6.x
Http::withOptions() with Guzzle’s Client constructor.on_trailers validation.MockHandler to test async workflows.
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
$mock = new MockHandler([new Response(200)]);
$client = new \GuzzleHttp\Client(['handler' => HandlerStack::create($mock)]);
How can I help you explore Laravel packages today?