mekras / psr7-client
PSR-7 compatible HTTP client library
Installs: 2 203
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 2
pkg:composer/mekras/psr7-client
This package has no released version yet, and little information is available.
README
PSR-7 compatible HTTP client library.
Simple cURL based PSR-7 compatible HTTP client library.
Attention!
This package will be replaced with php-http/curl-client.
Migrating to Httplug
- Add php-http/httplug to your project requirements.
- Replace
Mekras\Http\Client\CurlHttpClientandMekras\Interfaces\Http\Client\HttpClientInterfacewithHttp\Client\HttpClientin argument type hints - 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:
- Add any of php-http/client-implementation to your project and configure it.
- Replace instances of
Mekras\Http\Client\CurlHttpClientwith instances of chosenphp-http/client-implementation. - Remove
mekras/psr7-clientrequirement from yourcomposer.json.
Supported libraries
- guzzlehttp/psr7
- zendframework/zend-diactoros
- other by implementing ConnectorInterface
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 SSLtimeout(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'
]
]
);