Developed with love by KnpLabs Hire us for your project!
88

GuzzleBundle

by ludofleury

Debug your API Calls with a Symfony web profiler for guzzle

Guzzle Bundle Build Status Latest Stable Version Total Downloads

Provide a basic logger and an advanced profiler for Guzzle

  • The basic logger use the default Symfony app logger, it's safe to use in your production environement.
  • The advanced profiler is for debug purposes and will display a dedicated report available in the toolbar and Symfony Web Profiler

Installation

Add the composer requirements
javascript
{
"require-dev": {
"playbloom/guzzle-bundle": "v1.0.4"
},
}

Add the bundle to your Symfony app kernel
php
<?php
// in %your_project%/app/AppKernel.php
$bundles[] = new Playbloom\Bundle\GuzzleBundle\PlaybloomGuzzleBundle();
?>

To enable the advanced profiler & the toolbar/web profiler panel, add this line to your app/config/config_dev.yml
yml
playbloom_guzzle:
web_profiler: true

Guzzle client as a Symfony service

Concrete Guzzle client creation can be easily managed by the Symfony service container thanks to a simple factory configuration, in this case, you just need to tag your guzzle service(s) with playbloom_guzzle.client.

It will add the basic logger to your client(s). If the web_profiler is enabled in the current environement, it will also add the advanced profiler and display report on the Symfony toolbar/web profiler.

<service id="acme.client"
    class="%acme.client.class%"
    factory-class="%acme.client.class%"
    factory-method="factory">
    <!-- your arguments -->
    <tag name="playbloom_guzzle.client" />
</service>

Add the logger/profiler manually to a Guzzle client

If you need to handle the registration of the logger or profiler plugin manually, you can retrieve theses services from the Symfony container.

<?php

$client = new \Guzzle\Http\Client('https://my.api.com');

// basic logger service plugged & configured with the default Symfony app logger
$loggerPlugin = $container->get('playbloom_guzzle.client.plugin.logger');
$client->addSubscriber($loggerPlugin);

// advanced profiler for developement and debug, requires web_profiler to be enabled
$profilerPlugin = $container->get('playbloom_guzzle.client.plugin.profiler');
$client->addSubscriber($profilerPlugin);

?>

Customize your own profiler panel

If you need a custom profiler panel you can extend/reuse easily the data collector and profiler template from this bundle.

For example, you have a GithubBundle which interact with the Github API. You also have a Github profiler panel to debug your developement and you want to have the API requests profiled in this panel.

It's quite easy:
First, define your own GithubDataCollector extending the Playbloom\Bundle\GuzzleBundle\DataCollector\GuzzleDataCollector

Then extends the guzzle web profiler template
```twig
{% extends 'PlaybloomGuzzleBundle:Collector:guzzle.html.twig' %}

{% block panel %}

Github

Github API key: {{ collector.getApiKey }}
<!-- Some custom information -->

{% include 'PlaybloomGuzzleBundle:Profiler:requests.html.twig' with {'requests': collector.requests } %}

{% endblock %}
```

And finally declare your data collector
xml
<service id="data_collector.github" class="Acme\GithubBundle\DataCollector\GithubDataCollector">
<argument type="service" id="playbloom_guzzle.client.plugin.profiler"/>
<tag name="data_collector"
template="AcmeGithubBundle:Collector:github"
id="github"/>
</service>

That's it, now your profiler panel displays your custom information and the Guzzle API requests.

TODO

  • Add extra information about the client configuration itself (thanks to the guzzle service builder?)
  • Add clients|host|endpoint|time filters for http requests

Licence

This bundle is under the MIT license. See the complete license in the bundle

Credits

  • Swagger for the UI

Bitdeli Badge

playbloom_guzzle:
web_profiler: false
  • Merge pull request #25 from nurikabe/patch-1
    By ludofleury, 3 years ago
  • Fix link
    By nurikabe, 3 years ago
  • Merge pull request #24 from Nyholm/patch-1
    By ludofleury, 3 years ago
  • Added PHP 5.6 and HHVM to travis.yml
    By Nyholm, 3 years ago
  • Update README
    By ludofleury, 3 years ago
  • Merge pull request #18 from agallou/notice_zero
    By ludofleury, 3 years ago
  • Merge pull request #23 from classmarkets/typos
    By ludofleury, 3 years ago
  • fix typos
    By pschultz, 3 years ago
  • Merge pull request #21 from gigablah/fix-vendor
    By ludofleury, 3 years ago
  • Don't ignore vendor directory in resources
    By , 3 years ago
  • Merge pull request #20 from agallou/remove_strong
    By ludofleury, 3 years ago
  • remove "<strong>" displayed in response headers
    By agallou, 3 years ago
  • add a test to avoid a division by zero
    By agallou, 4 years ago
  • Merge pull request #17 from geoffreytran/patch-1
    By ludofleury, 4 years ago
  • Update services.xml
    By geoffreytran, 4 years ago
  • Add stable badge to the readme
    By ludofleury, 4 years ago
  • Add a Bitdeli badge to README
    By bitdeli-chef, 4 years ago
  • Merge pull request #15 from bitdeli-chef/master
    By ludofleury, 4 years ago
  • Update LICENCE
    By ludofleury, 4 years ago
  • Merge pull request #11 from ludofleury/refacto
    By ludofleury, 4 years ago
  • Refacto data collector
    By ludofleury, 4 years ago
  • Fixes composer definition for Symfony 2.1 to 2.3
    By ludofleury, 4 years ago
  • B64 encode image in the profiler
    By ludofleury, 4 years ago
  • Update to Symfony 2.3 add travis status
    By ludofleury, 4 years ago
  • Merge pull request #10 from ludofleury/tests
    By ludofleury, 4 years ago
  • Introduce unit test
    By ludofleury, 4 years ago
  • Removes Guzzle URL requirements
    By ludofleury, 4 years ago
  • Fixes typo & cs
    By ludofleury, 4 years ago
  • Remove .DS_Store
    By ludofleury, 4 years ago
  • Fixes typo in readme
    By ludofleury, 4 years ago