Skip to content

Repository files navigation

PSR-7 PHP Http Client

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.

<?phprequire_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.

<?phpuseLarium\Http\Client;
useHttp\Discovery\Psr17FactoryDiscovery;
usePsr\Http\Client\ClientExceptionInterface;
$request = Psr17FactoryDiscovery::findRequestFactory()->createRequest('GET', 'http://www.example.com');
$client = newClient();
try {
$response = $client->sendRequest($request);
# Response is a Psr\Http\Message\ResponseInterface instance implementation.
} catch (ClientExceptionInterface$e) {
//Resolve exception from client.
}

About

An http client implemention compatible with psr-7 http message.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages