kodus/http-client

Minimalist PSR-18 HTTP Client

1.0.0 2019-07-04 10:02 UTC

README

Minimalist PSR-18 HTTP Client.

PHP Version Build Status Code Coverage

  • No dependencies beyond PSR-17 HTTP Factory implementations
  • Streaming response: suitable for fetching large responses.
  • Accepts and decodes gzip encoded response content.

Note that this client does not follow redirects: PSR-18 doesn't specify - but this is a client, not a browser, and it's designed to be bootstrapped as a service instance: some dependents may need to know the status-code of the actual response; automatically following redirects makes that impossible.

Usage

Basic example using nyholm/psr7:

use Kodus\Http\HttpClient;
use Nyholm\Psr7\Factory\Psr17Factory;

// Bootstrap the client:

$http = new Psr17Factory();

$client = new HttpClient($http, $http);

// Perform a request:

$response = $client->sendRequest(
    $http->createRequest("GET", "https://postman-echo.com/get?foo=bar")
);

Please refer to PSR-18 documentation for details.