PHP code example of ovvio / http-client

1. Go to this page and download the library: Download ovvio/http-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ovvio / http-client example snippets



...

use Ovvio\Component\Http\HttpClient\HttpClientInterface;
use Ovvio\Component\Http\HttpClient\Request\Enum\RequestMethodEnum;
use Ovvio\Component\Http\HttpClient\Response\Enum\HttpResponseStatusCodeEnum;

...

    public function __construct(
        private readonly HttpClientInterface $httpClient,
    ) {
    }

...

    public function foo(FooDtoInterface $fooDto): void
    {

        ...

        /** @var \Uri\Rfc3986\Uri $url URL */
        $url = new \Uri\Rfc3986\Uri('https://ovvio.pro');
        $requestMethod = RequestMethodEnum::GET;

        $request = RequestFactory::create(
            url: $url,
            method: $requestMethod,
        );

        $request->addHeader(new AuthorizationRequestHeader('SOME TOKEN'));

        $response = $this->httpClient->request($request);
        if ($response->getStatusCode() !== HttpResponseStatusCodeEnum::OK) {
            // do something
        }

        ...

    }

...