larium / http-client
An http client implemention compatible with psr-7 http message.
2.0.4
2024-09-14 15:57 UTC
Requires
- php: >=8.1
- ext-curl: *
- php-http/discovery: ^1.19
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- laminas/laminas-diactoros: ^2.0
- phpunit/phpunit: ^10.0
Provides
README
An http client wrapping curl php extension, compatible with PSR-7 Http Message interfaces.
Installation
You can install this library using Composer
Composer from command line
In root directory of your project run through a console:
$ composer require "larium/http-client":"~1.0"
Composer from composer.json
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
Set up
After installation you must require autoload file from composer in to your boot php script.
<?php require_once 'vendor/autoload.php';
Basic usage
Using message factory discovery
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. }