Home » Php » guzzle – how to create GuzzleHttp api with php

guzzle – how to create GuzzleHttp api with php

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am creating GuzzleHttp rest APIs for this I have added GuzzleHttp via composer.

I don’t know how to handle AuthData(), class

require '../...../guzzle/vendor/autoload.php';
$url = "https://m2-rewards.com/api";

use GuzzleHttp\Client;

$client = new Client();
$auth = new AuthData();
$auth->id = '1';
$auth->token = 'someApiToken';
$response = $client->get($url . '/getNewsFeed', array(
    'auth' => base64_encode(json_encode($auth)),
    'verify' => false,
    'timeout' => 30 // seconds
));

$jsonData = json_decode($response->getBody(), true);
How to&Answers: