An http client wrapping curl php extension, compatible with PSR-7 Http Message interfaces.
You can install this library using Composer
In root directory of your project run through a console:
$ composer require "larium/http-client":"~1.0"
Include require line in your composer.json
file
{
"require": {
"larium/http-client": "~1.0"
}
}
and run from console in the root directory of your project:
$ composer update
After installation you must require autoload file from composer in to your boot php script.
<?php
require_once 'vendor/autoload.php';
You can use factory discovery to find any Request class that implements PSR-7 HTTP Message interfaces, to create the Request instance.
<?php
use Larium\Http\Client;
use Http\Discovery\Psr17FactoryDiscovery;
use Psr\Http\Client\ClientExceptionInterface;
$request = Psr17FactoryDiscovery::findRequestFactory()->createRequest('GET', 'http://www.example.com');
$client = new Client();
try {
$response = $client->sendRequest($request);
# Response is a Psr\Http\Message\ResponseInterface instance implementation.
} catch (ClientExceptionInterface $e) {
//Resolve exception from client.
}