setono / request-aware-http-client
一个装饰http客户端的请求日志库
v1.1.0
2023-05-19 11:34 UTC
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-09-07 13:26:40 UTC
README
此库将装饰Symfony HTTP客户端,使其能够检索完整的请求以供调试等使用。
安装
步骤1:下载
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" // } } }