mekras/psr7-client

This package is abandoned and no longer maintained. The author suggests using the php-http/curl-client package instead.

PSR-7 compatible HTTP client library

Maintainers

Details

github.com/mekras/psr7-client

This package has no released version yet, and little information is available.


README

PSR-7 compatible HTTP client library.

Latest Stable Version License Build Status Coverage Status

Simple cURL based PSR-7 compatible HTTP client library.

Attention!

This package will be replaced with php-http/curl-client.

Migrating to Httplug

  1. Add php-http/httplug to your project requirements.
  2. Replace Mekras\Http\Client\CurlHttpClient and Mekras\Interfaces\Http\Client\HttpClientInterface with Http\Client\HttpClient in argument type hints
  3. Replace send() method calls with sendRequest.

Mekras\Http\Client\CurlHttpClient supports both Mekras\Interfaces\Http\Client\HttpClientInterface and Http\Client\HttpClient interfaces, so migration can be done gradually.

After dropping last Mekras\Interfaces\Http\Client\HttpClientInterface usage:

  1. Add any of php-http/client-implementation to your project and configure it.
  2. Replace instances of Mekras\Http\Client\CurlHttpClient with instances of chosen php-http/client-implementation.
  3. Remove mekras/psr7-client requirement from your composer.json.

Supported libraries

Usage

use GuzzleHttp\Psr7\Request;
use Mekras\Http\Client\Connector\GuzzleConnector;
use Mekras\Http\Client\CurlHttpClient;

$client = new CurlHttpClient(new GuzzleConnector());
$request = new Request('GET', 'http://example.org/');
$response = $client->send($request);
echo $response->getBody()->getContents());

Options

Options can be set via second argument in constructor. Available options are:

  • connection_timeout (int) — connection timeout in seconds;
  • curl_options (array) — custom cURL options;
  • decode_content (bool) — see CURLOPT_ENCODING;
  • follow_redirects (bool) — automatically follow HTTP redirects;
  • max_redirects (int) — maximum nested redirects to follow;
  • ssl_verify_peer (bool) — verify peer when using SSL
  • timeout (int) — overall timeout in seconds.
  • use_cookies (bool) — save and send cookies;
use Mekras\Http\Client\Connector\GuzzleConnector;
use Mekras\Http\Client\CurlHttpClient;

$client = new CurlHttpClient(
    new GuzzleConnector(),
    [
        'timeout' => 60,
        'curl_options' => [
            CURLOPT_CAPATH => '/path/to/ca'
        ]
    ]
);