Immutable configuration
timeout(), retry() and every with*() method return a new client. A shared instance never keeps one caller's token, and all copies reuse one connection pool.
An immutable PSR-18 client on Guzzle. Configure it once and share it; tokens stay with their origin, retries never repeat a payment, and logs never show a secret.
use Solo\HttpClient\HttpClient;
$api = HttpClient::create('https://api.example.com/v1/')
->timeout(10)
->withToken($token)
->retry(3, 500);
$response = $api->get('users', ['query' => ['page' => 2]]);
if ($response->successful()) {
$users = $response->json('data'); // null when the body is not valid JSON
}
$api->post('users', ['json' => ['name' => 'Ada', 'email' => 'ada@example.com']]);The token goes only to https://api.example.com. A 404 or a 503 comes back as a response; only a failed transfer throws. Read the getting-started guide and the API reference for credentials, retries, uploads, logging and errors.
PHP 8.1+ is required, with Guzzle 7.15.2 or later.
composer require solophp/http-clientContinue with the getting-started guide.