/laravel-guzzle

This is a simple wrapper for Laravel around guzzlehttp/guzzle.

Primary LanguagePHPMIT LicenseMIT

Laravel Guzzle HTTP

Latest Version MIT License Offset Earth

GitHub Workflow Status StyleCI Total Downloads

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.

Installation

You can install the package via composer:

composer require astrotomic/laravel-guzzle

After this you should publish the package config and adjust it to your needs.

php artisan vendor:publish --provider="Astrotomic\LaravelGuzzle\LaravelGuzzleServiceProvider" --tag=config

Usage

Helper

You 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,
]);

Injection

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;
    }
}

Make

For sure you can also make a client via any app container.

$guzzle = app(\GuzzleHttp\ClientInterface::class, [
    'base_uri' => 'https://example.com',
]);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email dev.gummibeer@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Treeware

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

We offset our carbon footprint via Offset Earth