setono / request-aware-http-client
A library that decorates the http client with request logging
v1.0.0
2022-09-16 08:52 UTC
Requires
- php: ^7.4
- 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
- roave/security-advisories: dev-latest
- setono/code-quality-pack: ^2.2
- symfony/http-client: ^4.4 || ^5.4 || ^6.0
This package is auto-updated.
Last update: 2023-03-25 20:13:42 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" // } } }