PHP code example of borsch / http-client

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

    

borsch / http-client example snippets




use Borsch\Http\Client;
use Borsch\Http\Request; // PSR-7 Request implementation from any package (see below)

$client = new Client();
$client->setResponseClassName(
    \Borsch\Http\Response::class
);

$request = new Request('GET', 'https://dog.ceo/api/breeds/list/all');
$response = $client->sendRequest($request);



use Borsch\Http\Client;
use Slim\Psr7\Response as SlimPhpResponse;

$client = new Client();
$client->setResponseClassName(SlimPhpResponse::class);



use Borsch\Http\Client;
use Nyholm\Psr7\Factory\Psr17Factory;

$client = new Client();
$client->setResponseClassName(Psr17Factory::class);



use Borsch\Http\Client;
use Nyholm\Psr7\Factory\Psr17Factory;

$client = new Client();
$client->setResponseClassName(Psr17Factory::class);

$request = (new Psr17Factory())->createRequest('GET', 'https://dog.ceo/api/breeds/list/all');
$response = $client
    ->setCurlOption(CURLOPT_CAINFO, dirname(__FILE__).'/cacert.pem') // will work
    ->setCurlOption(CURLOPT_CUSTOMREQUEST, 'POST') // will not work as already used by Borsch\Http\Client
    ->sendRequest($request);

$options = [
    CURLOPT_CAINFO => dirname(__FILE__).'/cacert.pem',
    // etc.
]