Use this adapter when you need framework-neutral client interoperability.
$config->generationTarget = GenerationTarget::Client;
$config->httpClient = HttpClientAdapter::Psr18;
$config->httpClientVersion = '1.1';
public function __construct(
private readonly ClientInterface $httpClient,
private readonly string $baseUrl,
private readonly RequestFactoryInterface $requestFactory,
private readonly StreamFactoryInterface $streamFactory,
) {
}
$url = $this->baseUrl . "/pets/{$petId}";
$request = $this->requestFactory->createRequest('GET', $url);
$response = $this->httpClient->sendRequest($request);
For JSON bodies, the generator sets content type and stream body:
$bodyStream = $this->streamFactory->createStream(json_encode($body->toArray(), JSON_THROW_ON_ERROR));
$request = $request->withHeader('Content-Type', 'application/json')->withBody($bodyStream);
Response body is decoded with json_decode(..., JSON_THROW_ON_ERROR) and then mapped to generated models.