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?
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()
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();
});