composer require guzzlehttp/guzzle
touch index.php
nano index.php
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'base_uri' => 'http://localhost/api/',
'timeout' => 2.0,
]);
$response = $client->request('POST', 'auth/login', ['json'=>['username'=>'admin', 'password'=>'secret']]);
in this example, Our API returned this JSON string
{
"result" : "OK",
"jwt" : "blablabla"
}
$cod = $response->getStatusCode();
echo $code . "\n";
$body = (string) $response->getBody();
$arrBody = json_decode($body, true);
$result = $arrBody['result'];
echo $result . "\n";
$jwt = $arrBody['jwt'];
echo $jwt;