graham-campbell/guzzle-factory
Simple factory for creating Guzzle HTTP clients with sensible defaults. One-liner client creation via GuzzleFactory::make(), with optional config like base_uri. Supports PHP 7.4–8.5 and integrates cleanly in modern PHP/Laravel apps.
Pros:
config/services.php or AppServiceProvider). Reduces boilerplate and enforces consistency across HTTP clients.Cons:
guzzlehttp/middleware) for advanced use cases.HttpClient).$app->singleton(GuzzleFactory::class, fn() => new GuzzleFactory());
config/services.php:
'guzzle' => [
'timeout' => env('HTTP_TIMEOUT', 30),
'retries' => 3,
'defaults' => [
'base_uri' => env('API_BASE_URI'),
],
],
Guzzle facade or helper to abstract factory usage:
facade_root('Guzzle', 'GrahamCampbell\GuzzleFactory\GuzzleFactory');
$this->app->instance(GuzzleFactory::class, Mockery::mock(GuzzleFactory::class));
public function __construct(private GuzzleFactory $factory) {}
composer.json to avoid version skew:
"require": {
"guzzlehttp/guzzle": "^7.11",
"graham-campbell/guzzle-factory": "^8.0"
}
guzzlehttp/middleware).composer require graham-campbell/guzzle-factory).AppServiceProvider).config/services.php.composer require guzzlehttp/guzzle:^7.11 graham-campbell/guzzle-factory:^8.0
config/services.php).| Failure Scenario | Impact | **Mit
How can I help you explore Laravel packages today?