use GuzzleHttp\Client; $client = new Client(); $emitter = $client->getEmitter(); $emitter->on('before', function ($event) { echo 'Request has been sent'; });
use GuzzleHttp\Client; $client = new Client(); $emitter = $client->getEmitter(); $emitter->on('complete', function ($event) { $response = $event->getResponse(); echo $response->getBody(); }); $response = $client->get('http://example.com');In this example, we are attaching a listener to the 'complete' event that is emitted when a response is received. The callback function will receive the response object and display the response body. Package library: GuzzleHttp Summary: GuzzleHttp Client getEmitter method allows you to listen and emit events that are emitted during the API request lifecycle, such as before and after sending a request or receiving a response.