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:
//autoload.php
//...
$loader->registerNamespaces(array(
//...
'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('http://someurl.com');
$response = $req->send();
print_r($response);
//...
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




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?