Guzzle integration into Nette Framework
composer require contributte/guzzlette
extensions:
guzzle: Contributte\Guzzlette\DI\GuzzleExtension
guzzle:
debug: %debugMode%
client: # config for GuzzleHttp\Client
timeout: 30
Get guzzle from DIC instead of creating a new one. Everything else is in Guzzle documentation.
use Contributte\Guzzlette\ClientFactory;
use GuzzleHttp\Client;
use Nette\Application\UI\Presenter;
class ExamplePresenter extends Presenter {
/** @var Client */
private $guzzle;
public function injectGuzzle(Client $guzzle): void
{
$this->guzzle = $guzzle
}
// Alternatively you could create new instance through ClientFactory
public function injectGuzzle(ClientFactory $factory): void
{
$this->guzzle = $factory->createClient([
'timeout' => 30
]);
}
}