symfony4symfony-http-client

How to make HTTPClient request appear in Symfony profiler?


I'm using Symfony 4.4.7 and making http requests with HTTPClient (Symfony\Component\HttpClient\HttpClient) but requests doesn't shown in profiler. How to make this profiler tab work?


Solution

  • I solved it.

    You should use HttpClient using Dependency Injection then requests will appear in Profiler.

    // services.yaml
    App\Service\SomeService:
        arguments: 
            $httpClient: '@http_client'
    
    ...
    
    use Symfony\Contracts\HttpClient\HttpClientInterface;
    ...
    class SomeService
    {
        protected $httpClient;
        public function __construct(HttpClientInterface $httpClient)
        {
            $this->httpClient = $httpClient;
        }
        ...
    }