Skip to content

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

License

Notifications You must be signed in to change notification settings

Larium/http-client

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.

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