sunrise/http-client-curl

Sunrise // HTTP cURL client for PHP 7.1+ based on PSR-18

v1.2.0 2019-05-29 23:14 UTC

README

Gitter Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads License

Installation

composer require sunrise/http-client-curl

How to use?

Sunrise HTTP Factory

composer require sunrise/http-factory
use Sunrise\Http\Client\Curl\Client;
use Sunrise\Http\Factory\RequestFactory;
use Sunrise\Http\Factory\ResponseFactory;

$client = new Client(new ResponseFactory());
$request = (new RequestFactory)->createRequest('GET', 'http://php.net/');
$response = $client->sendRequest($request);

// just use PSR-7 Response object...

Zend Diactoros

composer require zendframework/zend-diactoros
use Sunrise\Http\Client\Curl\Client;
use Zend\Diactoros\RequestFactory;
use Zend\Diactoros\ResponseFactory;

$client = new Client(new ResponseFactory());
$request = (new RequestFactory)->createRequest('GET', 'http://php.net/');
$response = $client->sendRequest($request);

// just use PSR-7 Response object...

cURL options

$client = new Client(new ResponseFactory(), [
    \CURLOPT_AUTOREFERER => true,
    \CURLOPT_FOLLOWLOCATION => true,
    \CURLOPT_MAXREDIRS => 10,
]);

Test run

php vendor/bin/phpunit --colors=always --coverage-text

Api documentation

https://phpdoc.fenric.ru/

Useful links