So in working with my latest project I needed to make some REST calls through PHP. After doing a bit of research I decided to use Guzzle http://guzzlephp.org/. The reason why I decided to use Guzzle is that it’s simple, easily extensible, and has a testing framework. So I’m going to make a few assumptions in this tutorial. I’m assuming that you’ve already got Symfony2 up and running on your machine. If not, go to http://symfony.com/ and follow the Get Started link to get up and running. So now without further ado!
- Navigate to your Symfony2 location and run this:
git submodule add git://github.com/guzzle/guzzle.git vendor/guzzle
git submodule add git://github.com/ddeboer/GuzzleBundler vendor/bundles/Ddeboer/GuzzleBundle
- Now go to your Autoload.php (app/autoload.php) file and register namespaces.
'Guzzle' => __DIR__.'/../vendor/guzzle/src',
'Ddeboer' => __DIR__.'/../vendor/bundles',
- Add the GuzzleBundle to your application kernel. (app/AppKernel.php)
public function registerBundles()
- The last step you need to do is set up your Guzzle service builder. (app/config/config.yml)
I had some problems with the cache section so you can remove that if you run into any problems.
Now you’re all set up to start sending REST requests through Guzzle in your Symfony2 application. Next blog post I’ll show you how to use Guzzle’s extensibility (that should definitely be a word) to turn your REST calls into an API that’s super easy to use.