<?php
/**
* this trait to handle our requests to micro-services
*/
namespace App\Traits;
use GuzzleHttp\Client;
trait ConsumeExternalService
{
/**
* Send request to any service
* @param $method
* @param $requestUrl
* @param array $formParams
* @param array $headers
* @return string
*/
public function performRequest($method, $requestUrl, $formParams = [], $headers = [])
{
$client = new Client([
'base_uri' => $this->baseUri,
'verify' => false
]);
if(isset($this->secret))
{
$headers['Authorization'] = $this->secret;
}
$response = $client->request($method, $requestUrl, [
'form_params' => $formParams,
'headers' => $headers,
]);
return $response->getBody()->getContents();
}
}
|