HttpClient
The framework HTTP client: a PSR-18 ClientInterface wrapping an underlying transport, adding base-URI resolution, default headers, a transient-failure retry policy, ergonomic verb helpers, and — the payoff for the whole abstraction — the central egress seam for telemetry.
Every outbound request opens a CLIENT-kind span and injects W3C traceparent so downstream services continue the trace (the outbound half of the request-tracing story, previously blocked on the absence of exactly this client).
Obtain instances via HttpClientFactory (memoized, named) rather than constructing directly, so a worker reuses one client per name for its lifetime instead of rebuilding on every call.
Synopsis
Section titled “Synopsis”final class HttpClient implements ClientInterface
| Implements | ClientInterface |
| Source | Http/Client/HttpClient.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(ClientInterface $transport, string $baseUri = '', array $defaultHeaders = [], int $retries = 0, int $retryBaseDelayMs = 100, Psr17Factory $psr17 = new Psr17Factory(…)): mixed
| Parameter | Type | Description |
|---|---|---|
$transport | ClientInterface | |
$baseUri | string | |
$defaultHeaders | array | |
$retries | int | |
$retryBaseDelayMs | int | |
$psr17 | Psr17Factory |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
delete(string $uri, array{headers?: array<string, string>} $options = []): ResponseInterface | |
fromConfig(HttpClientConfig $config): HttpClient | Builds a client from a resolved HttpClientConfig, taking its transport, base URI, default headers and retry policy. |
get(string $uri, array{headers?: array<string, string>} $options = []): ResponseInterface | |
post(string $uri, array{headers?: array<string, string>, body?: string} $options = []): ResponseInterface | |
put(string $uri, array{headers?: array<string, string>, body?: string} $options = []): ResponseInterface | |
request(string $method, string $uri, array{headers?: array<string, string>, body?: string} $options = []): ResponseInterface | Ergonomic request builder. |
sendRequest(RequestInterface $request): ResponseInterface | PSR-18 entry point. |
delete()
Section titled “delete()”public function delete(string $uri, array{headers?: array<string, string>} $options = []): ResponseInterface
| Parameter | Type | Description |
|---|---|---|
$uri | string | |
$options | array{headers?: array<string, string>} |
Returns ResponseInterface
fromConfig()
Section titled “fromConfig()”public static function fromConfig(HttpClientConfig $config): HttpClient
Builds a client from a resolved HttpClientConfig, taking its transport, base URI, default headers and retry policy.
The PSR-17 factory is not configurable this way: the client uses its own default.
| Parameter | Type | Description |
|---|---|---|
$config | HttpClientConfig |
Returns HttpClient
public function get(string $uri, array{headers?: array<string, string>} $options = []): ResponseInterface
| Parameter | Type | Description |
|---|---|---|
$uri | string | |
$options | array{headers?: array<string, string>} |
Returns ResponseInterface
post()
Section titled “post()”public function post(string $uri, array{headers?: array<string, string>, body?: string} $options = []): ResponseInterface
| Parameter | Type | Description |
|---|---|---|
$uri | string | |
$options | array{headers?: array<string, string>, body?: string} |
Returns ResponseInterface
public function put(string $uri, array{headers?: array<string, string>, body?: string} $options = []): ResponseInterface
| Parameter | Type | Description |
|---|---|---|
$uri | string | |
$options | array{headers?: array<string, string>, body?: string} |
Returns ResponseInterface
request()
Section titled “request()”public function request(string $method, string $uri, array{headers?: array<string, string>, body?: string} $options = []): ResponseInterface
Ergonomic request builder.
| Parameter | Type | Description |
|---|---|---|
$method | string | |
$uri | string | |
$options | array{headers?: array<string, string>, body?: string} |
Returns ResponseInterface
sendRequest()
Section titled “sendRequest()”public function sendRequest(RequestInterface $request): ResponseInterface
PSR-18 entry point.
Applies default headers, telemetry, and the retry policy.
| Parameter | Type | Description |
|---|---|---|
$request | RequestInterface |
Returns ResponseInterface