Use this adapter when you need framework-neutral client interoperability.
$config->generationTarget = GenerationTarget::Client;
$config->httpClient = HttpClientAdapter::Psr18;
public function __construct(
private readonly ClientInterface $httpClient,
private readonly string $baseUrl,
private readonly RequestFactoryInterface $requestFactory,
private readonly StreamFactoryInterface $streamFactory,
) {
}
$url = rtrim($this->baseUrl, '/') . '/pets/' . rawurlencode((string) $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->toRequestArray(), JSON_THROW_ON_ERROR));
$request = $request->withHeader('Content-Type', 'application/json')->withBody($bodyStream);
The response body is decoded by the generated decodeJsonResponse() helper,
which rejects non-JSON content types and invalid JSON with an
UnexpectedValueException, and then mapped to generated models.