HttpClientConfig
Mutable, fluent configuration for a named HTTP client, populated inside a HttpClientFactory::configure() callback (the dotnet AddHttpClient("name", c => ...) analogue).
Turned into an immutable HttpClient once, then memoized by the factory.
Synopsis
Section titled “Synopsis”final class HttpClientConfig
| Source | Http/Client/HttpClientConfig.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
baseUri(string $baseUri): HttpClientConfig | Base URI prepended to relative request paths (e.g. |
getBaseUri(): string | Returns the configured base URI with any trailing slash removed, or an empty string when none was set. |
getHeaders(): array<string, string> | |
getRetries(): int | Returns how many extra attempts a transient failure earns; zero, the default, means no retrying. |
getRetryBaseDelayMs(): int | Returns the first backoff delay in milliseconds, from which later retries grow exponentially; 100 unless HttpClientConfig::retry() changed it. |
getTransport(): ClientInterface | Returns the PSR-18 transport this client will use. |
header(string $name, string $value): HttpClientConfig | A default header sent with every request unless the request already sets it. |
headers(array<string, string> $headers): HttpClientConfig | |
retry(int $attempts, int $baseDelayMs = 100): HttpClientConfig | Retry transient failures (network errors, HTTP 429, HTTP 5xx) up to $attempts extra times, with exponential backoff from $baseDelayMs. |
transport(ClientInterface $transport): HttpClientConfig | Override the underlying PSR-18 transport for this client (default: TransportFactory::default()). |
baseUri()
Section titled “baseUri()”public function baseUri(string $baseUri): HttpClientConfig
Base URI prepended to relative request paths (e.g.
| Parameter | Type | Description |
|---|---|---|
$baseUri | string |
Returns HttpClientConfig
getBaseUri()
Section titled “getBaseUri()”public function getBaseUri(): string
Returns the configured base URI with any trailing slash removed, or an empty string when none was set.
Returns string
getHeaders()
Section titled “getHeaders()”public function getHeaders(): array<string, string>
Returns array``<``string``, ``string``>
getRetries()
Section titled “getRetries()”public function getRetries(): int
Returns how many extra attempts a transient failure earns; zero, the default, means no retrying.
Returns int
getRetryBaseDelayMs()
Section titled “getRetryBaseDelayMs()”public function getRetryBaseDelayMs(): int
Returns the first backoff delay in milliseconds, from which later retries grow exponentially; 100 unless HttpClientConfig::retry() changed it.
Returns int
getTransport()
Section titled “getTransport()”public function getTransport(): ClientInterface
Returns the PSR-18 transport this client will use.
When HttpClientConfig::transport() was never called, TransportFactory::default() is asked for one and the result is memoised, so every request from this config shares a transport.
Returns ClientInterface
header()
Section titled “header()”public function header(string $name, string $value): HttpClientConfig
A default header sent with every request unless the request already sets it.
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$value | string |
Returns HttpClientConfig
headers()
Section titled “headers()”public function headers(array<string, string> $headers): HttpClientConfig
| Parameter | Type | Description |
|---|---|---|
$headers | array``<``string``, ``string``> |
Returns HttpClientConfig
retry()
Section titled “retry()”public function retry(int $attempts, int $baseDelayMs = 100): HttpClientConfig
Retry transient failures (network errors, HTTP 429, HTTP 5xx) up to $attempts extra times, with exponential backoff from $baseDelayMs.
| Parameter | Type | Description |
|---|---|---|
$attempts | int | |
$baseDelayMs | int |
Returns HttpClientConfig
transport()
Section titled “transport()”public function transport(ClientInterface $transport): HttpClientConfig
Override the underlying PSR-18 transport for this client (default: TransportFactory::default()).
| Parameter | Type | Description |
|---|---|---|
$transport | ClientInterface |
Returns HttpClientConfig