I'm trying to read the data from an api using Guzzle 6, but have been unable to find any relevant examples. Each line returned from the api is a json object - the aim is to process each line as it is received.
The code I have so far is below, could someone advise where I have got confused?
Thanks
ini_set('display_errors', true);
require('vendor/autoload.php');
use GuzzleHttp\Client;
use GuzzleHttp\Stream\Stream;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
$token = "1234";
$client = new Client(['base_uri' => 'https://apiurl.com'], ['stream' => true, 'debug'=>true]);
$headers = [
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
];
$response = $client->request('GET', '?foo=bar', ['headers' => $headers ]);
$body = $response->getBody();
while (!$body->eof()) {
echo $body->read(1024);
}