Skip to content

Setono/request-aware-http-client

Repository files navigation

Symfony Request Aware HTTP Client

Latest Version Software License Build Status Code Coverage

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"
        // }
    }
}

About

This library will decorate Symfony HTTP client and make it possible to retrieve full requests for debugging etc.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages