Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Setono/HttpClientBundle

Repository files navigation

Symfony HTTP Client Bundle

Latest Version Software License Build Status

USE https://github.com/Setono/request-aware-http-client INSTEAD

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

Installation

Step 1: Download

$ composer require setono/http-client-bundle

Step 2: Enable the bundle

If you use Symfony Flex it will be enabled automatically. Else you need to add it to the config/bundles.php:

<?php
// config/bundles.php

return [
    // ...

    Setono\HttpClientBundle\SetonoHttpClientBundle::class => ['all' => true],

    // ...
];

Usage

Right now you manually decorate your HTTP client. In the future this will be done automatically for you.

<?php
use Setono\HttpClientBundle\HttpClient\RequestAwareHttpClient;
use Setono\HttpClientBundle\HttpClient\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->getRequestFromResponse($response);

        echo $request->asString();
        
        // Outputs:
        // POST https://httpbin.org/post {"name":"John Doe"}
    }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Languages