PHP code example of williamespindola / abstract-http-client

1. Go to this page and download the library: Download williamespindola/abstract-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/ */

    

williamespindola / abstract-http-client example snippets


...
use WilliamEspindola\AbstractHTTPClient\AbstractRequest;
use GuzzleHttp\Psr7\Response;
...

final class MyRequest extends AbstractRequest
{
    /**
     * @var string $endPoint End point of resource
     */
    protected $endPoint = '/some/end-point/:someStringParam';
    
    public function request(string $someStringParam, int $someIntParam): Response
    {
        $this->setParameters([':someStringParam' => $someStringParam]);
    
        $this->httpClient->setOptions(['form_params' => ['someIntParam' => $someIntParam]]);
   
        return $this->httpClient->request('POST', $this->getURI());
    }
}

use GuzzleHttp\Client;
use WilliamEspindola\AbstractHTTPClient\MyRequest;
use WilliamEspindola\AbstractHTTPClient\Client\GuzzleClient;

$instance = new MyRequest(new GuzzleClient(new Client), 'http://url');

namespace WilliamEspindola\AbstractHTTPClient

...
use WilliamEspindola\AbstractHTTPClient\Client\AbstractRequest;
use WilliamEspindola\AbstractHTTPClient\Client\QueryString\ExtraQueryString;
use GuzzleHttp\Psr7\Response;
...

final class MyRequest extends AbstractRequest
{
    use ExtraQueryString;
    
    /**
     * @var string $endPoint End point of resource
     */
    protected $endPoint = '/some/end-point/:someStringParam';
    
    public function request(string $someStringParam, int $someIntParam): Response
    {
        $this->setParameters([':someStringParam' => $someStringParam]);
    
        $this->httpClient->setOptions(['form_params' => ['someIntParam' => $someIntParam]]);
   
        return $this->httpClient
            ->request(
                'POST', 
                $this->getUriWithExtraString($this->getURI())
            );
    }
}