$client = new \GuzzleHttp\Client(); $response = $client->request('GET', 'https://jsonplaceholder.typicode.com/posts/1'); echo $response->getBody();
$client = new \GuzzleHttp\Client(); $response = $client->request('GET', 'https://jsonplaceholder.typicode.com/posts', [ 'query' => [ 'userId' => 1 ] ]); echo $response->getBody();
$client = new \GuzzleHttp\Client(); $response = $client->request('GET', 'https://api.example.com/user/123', [ 'headers' => [ 'Authorization' => 'Bearer ' . $accessToken, 'Content-Type' => 'application/json' ], 'auth' => ['username', 'password'] ]); echo $response->getBody();In this example, we are sending a GET request to an API with custom headers (`Authorization`, `Content-Type`) and authentication (`auth` headers). We are also getting the response body using the `getBody()` method. Package/library: GuzzleHttp\Client (version 6.5.5)