How to solve "There is no extension able to load the configuration for 'monolog.http_client' "

1.5k Views Asked by At

I want to use the HttpClientInterface from symfony, so i added it in __construct like this:

private HttpClientInterface $client;

/**
* @param HttpClientInterface $client
*/
public function __construct(
   HttpClientInterface $client
) {
    $this->client = $client;
}

And just a simple request in my function:

$response = $this->client->request(
  'GET',
  'https://mywebsite.com/api/call/myId'
);

So when i try to run it i get this error:

Cannot autowire service "App\MyService": argument "$client" of method "__construct()" references interface "Symfony\Contracts\HttpClient\HttpClientInterface" but no such service exists. You should maybe alias this interface to the existing "monolog.http_client" service.

I tried to add it to services as it said above but i also got an error:

Like this (monolog.http_client: or http_client:)

Error: here is no extension able to load the configuration for "monolog.http_client"

So i really have no idea how to solve this problem!!

2

There are 2 best solutions below

2
On BEST ANSWER

I had to add http_client: under framework: in services.yml

1
On

The component is just probably not in your vendors. Try php bin/console debug:container httpClient if it can't find the service, install it with composer require "symfony/http-client"