Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GKMelbo's avatar

Guzzle error with Jeffreys example

I'm trying out the example Jeffrey give us in the lesson "Easy HTTP Requests" but get an error saying it needs to be an array. Here is my code:
Route::get('users/{username}', function ($username)
{
$client = new \GuzzleHttp\Client('https://api.github.com/');
$response = $client->get("users/$username")->send();
dd($response->json());
});
Does anyone see what I'm doing wrong?

0 likes
4 replies
GKMelbo's avatar

Ok. So now I have:
Route::get('users/{username}', function ($username)
{
$client = new \GuzzleHttp\Client(['base_uri' => 'https://api.github.com/']);
$response = $client->get("users/$username")->send();
dd($response->json());
});

But then I receive this error:
Call to undefined method GuzzleHttp\Psr7\Response::send()

GKMelbo's avatar

I see. getContents() didn't work, but if I simply use:
$response = $client->get("users/$username");
dd($response);

I receive the following:
Response {#141 ▼
-reasonPhrase: "OK"
-statusCode: 200
-headers: array:22 [▶]
-headerLines: array:22 [▶]
-protocol: "1.1"
-stream: Stream {#139 ▶}
}

But it doesn't display the public user information like in Jeffreys video.

EDIT: I finally got it working! The result doesn't show as a list like in the example video, but it displays from left to right. Anyway, the important thing is that it works. I believe the reason it didn't work following Jeffreys video is that Guzzle now is a newer version and has deprecated some of the methods. Anyone able to confirm this?

So here is the code that ended up working for me:
Route::get('users/{username}', function ($username)
{
$client = new GuzzleHttp\Client(['base_uri' => 'https://api.github.com/']);
$response = $client->get("users/$username");
echo $response->getBody();
die();
});

Thanks for the help taijuten!

1 like

Please or to participate in this conversation.