add simple test data to use loaded Guzzle http client

This commit is contained in:
2025-12-13 23:23:38 +03:30
parent 666f37eea2
commit 14c689f058

35
src/index.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
require '../vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
$client = new Client();
try {
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
} catch (GuzzleException $e) {
echo $e->getMessage();
return;
}
echo $response->getStatusCode() . PHP_EOL;
echo $response->getHeaderLine('content-type') . PHP_EOL;
echo $response->getBody() . PHP_EOL;
// asynchronous
$request = new Request('GET', 'https://httpbin.org');
$promise = $client
->sendAsync($request)
->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
echo "before waiting for response" . PHP_EOL;
$promise->wait();
echo "after waiting for response" . PHP_EOL;