This library will decorate Symfony HTTP client and make it possible to retrieve full requests for debugging etc.
composer require setono/request-aware-http-client<?php
use Setono\RequestAwareHttpClient\RequestAwareHttpClient;
use Setono\RequestAwareHttpClient\RequestAwareHttpClientInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class YourService
{
private RequestAwareHttpClientInterface $httpClient;
public function __construct(HttpClientInterface $httpClient)
{
$this->httpClient = new RequestAwareHttpClient($httpClient);
}
public function doSomething(): void
{
$response = $this->httpClient->request('POST', 'https://httpbin.org/post', [
'json' => ['name' => 'John Doe']
]);
$request = $this->httpClient->getRequest($response);
echo $request->toString();
// Outputs:
// POST https://httpbin.org/post
// {
// "name": "John Doe"
// }
}
}