Http client client for le7 PHP MVC framework or any PSR project This is an simple PSR http-client implementation
This project provides HTTP clients that uses Curl and standard PHP functions to make requests.
- Create HTTP requests using cURL
- Create HTTP requests using standard PHP tools
- PHP 8.0 or higher
- Composer (for installing dependencies)
- Install via composer:
composer require rnr1721/le7-http-client
composer test
In this example, I use Nyholm PSR library, but you can use any, Guzzle for example
use Nyholm\Psr7\Factory\Psr17Factory;
use Core\HttpClient\HttpClientCurl;
use Core\HttpClient\HttpClientDefault;
// Create PSR factories. Nyholm realisation is a single factory to all
$psr17Factory = new Psr17Factory();
// Get Curl http client
$httpClientCurl = new HttpClientCurl(
$psr17Factory // ResponseFactoryInterface
)
// Or if need get PHP http client
$httpClientPhp = new HttpClientDefault(
$psr17Factory // ResponseFactoryInterface
)
// now we can use it:
$request = $psr17Factory->createRequest('GET', 'http://tnyholm.se');
$response = $httpClientCurl->sendRequest($request);