setono / request-aware-http-client
A library that decorates the http client with request logging
Installs: 3 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: >=8.1
- ext-json: *
- psr/log: ^1.1 || ^2.0 || ^3.0
- symfony/http-client-contracts: ^1.1 || ^2.3 || ^3.1
- symfony/service-contracts: ^1.1 || ^2.5 || ^3.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- setono/code-quality-pack: ^2.4
- symfony/http-client: ^5.4 || ^6.0
This package is auto-updated.
Last update: 2024-12-07 14:04:32 UTC
README
This library will decorate Symfony HTTP client and make it possible to retrieve full requests for debugging etc.
Installation
Step 1: Download
composer require setono/request-aware-http-client
Usage
<?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" // } } }