This is a simple wrapper for Laravel around guzzlehttp/guzzle. It provides container bindings and a little helper function.
The idea was born by reading Always set a timeout for Guzzle requests inside a queued job by @themsaid.
Why limit it to the queue? At the end the problem applies to every curl request.
That's why this package comes with a default config which is applied to every guzzle instance build by this package.
You can install the package via composer:
composer require astrotomic/laravel-guzzleAfter this you should publish the package config and adjust it to your needs.
php artisan vendor:publish --provider="Astrotomic\LaravelGuzzle\LaravelGuzzleServiceProvider" --tag=configYou can use the helper function to create a new instance of GuzzleHttp\Client. The helper function has two optional arguments. The base_uri and a config array. Both are merged with the default config defined in the package config file.
$guzzle = guzzle('https://example.com', [
RequestOptions::CONNECT_TIMEOUT => 3,
]);Because this package binds the guzzle client with the container you can use injection. The only downside is that you aren't able to set a base_uri this way.
class MyClass
{
public function __construct(\GuzzleHttp\ClientInterface $guzzle)
{
$this->guzzle = $guzzle;
}
}For sure you can also make a client via any app container.
$guzzle = app(\GuzzleHttp\ClientInterface::class, [
'base_uri' => 'https://example.com',
]);composer testPlease see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email dev.gummibeer@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree.
It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats.
You can buy trees at https://offset.earth/treeware
Read more about Treeware at https://treeware.earth