Symfony2 web client – Guzzle setup

Featured Image ©

Once I made some of REST API features/calls in my project, except unit testing, there was a need for me to build some kind of web client inside my project, so I could have a screen with different options to custom build my REST calls and analyze results.

There was an option to build either JavaScript, .NET or some other kind of web client with pre-configured parameters that I need in my API calls to analyze and test my new REST API. But because I wanted to have this client available to other developers that use different operating systems, I decided to build it in Php with help of AJAX to make parametrized calls to my REST API and display results in screen.

I made some kind of ‘investigation’ on Google to find some Php web client library higher level then cURL that I can use in my Symfony2 project easily.

There are several php web client libraries out there. But if you want to use Symfony2 – ready php web client library, I suggest use the Guzzle because of many available options for fine tuning your php web client.
Also except Guzzle php library, there is a Symfony2 bundle for integration with your Symfony2 project available: GuzzleBundle

Let’s setup our project for Guzzle to be used:

First go to links above and download Guzzle library from github, unpack it inside ‘vendor’ folder like this:


Then download Guzzle bundle for Symfony2 from above link and place it in vendor like this:


Don’t forget to add it inside autoload.php and AppKernel.php properly in order to make it work:

    'Guzzle'           => __DIR__.'/../vendor/guzzle/src',
    'Ddeboer'          => __DIR__.'/../vendor/bundles',
// AppKernel.php
    public function registerBundles()
        $bundles = array(
            new Ddeboer\GuzzleBundle\DdeboerGuzzleBundle(),

And now is time to use it inside your controller:

// somecontroller.php
$client = new \Guzzle\Service\Client();
$req = $client->get('');
$response = $req->send();

And that’s it for now. In some of next articles, I will explain how to set some cUrl parameters to use client with SSL unsigned certificate, how to make GET, POST calls, use callback for retreiving results and, of course how to use it with cookie support…

Cheers for now 🙂


  1. Hello,

    Thanks for sharing it. When I add GuzzleBundle I encounter an error
    Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap handling the post-update-cmd event terminated with an exception [RuntimeException] An error occurred when generating the bootstrap file.

    When I try to clear my cache i got this error

    php app/console cache:clear

    Fatal error: Class ‘Ddeboer\GuzzleBundle\DdeboerGuzzleBundle’ not found in /data/home/jchannagiri/codebase/ppa/app/AppKernel.php on line 24

    Call Stack:
    0.0004 224768 1. {main}() /data/home/jchannagiri/codebase/ppa/app/console:0
    0.0649 3316344 2. Symfony\Component\Console\Application->run() /data/home/jchannagiri/codebase/ppa/app/console:27
    0.0707 3526112 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /data/home/jchannagiri/codebase/ppa/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
    0.0707 3526416 4. Symfony\Component\HttpKernel\Kernel->boot() /data/home/jchannagiri/codebase/ppa/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:70
    0.0707 3526640 5. Symfony\Component\HttpKernel\Kernel->initializeBundles() /data/home/jchannagiri/codebase/ppa/app/bootstrap.php.cache:2372
    0.0707 3527328 6. AppKernel->registerBundles() /data/home/jchannagiri/codebase/ppa/app/bootstrap.php.cache:2542

    Please help me to solve the problem.

    Thanks in advance.

  2. Hi Darko. Thanks for discovering Guzzle. I used I see that Guzzle has a lot of features, but how is it comparing to Buzz? Can Guzzle be used instead of Goutte in Symfony2? What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.