require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client(); $response = $client->get('https://api.example.com/data'); $data = $response->getBody(); echo $data;
require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\RequestOptions; $client = new Client(); $data = [ 'name' => 'John Doe', 'email' => 'johndoe@example.com' ]; $jsonData = json_encode($data); $response = $client->post('https://api.example.com/user', [ RequestOptions::JSON => $jsonData ]); echo $response->getStatusCode();This code sends a POST request to the specified URL with JSON data in the request body. Note: When using Guzzle, you need to have the package installed in your project. You can install it using Composer, which is a popular PHP dependency manager.