mobilebackendgateway/app/Traits/ConsumesExternalService.php

33 lines
830 B
PHP
Raw Normal View History

<?php
namespace App\Traits;
use GuzzleHttp\Client;
trait ConsumesExternalService
{
/**
* Envoie une requete a un service
* @param $method
* @param $requestUrl
* @param array $body
* @param array $formParams
* @param array $headers
* @return string
*/
2020-04-28 17:35:28 +00:00
public function perfomRequest($method, $requestUrl, $body = [], $headers = [], $formParams = [])
{
$client = new Client([
'base_uri' => $this->baseUri,
]);
2020-04-15 23:09:27 +00:00
if(isset($this->key)){
2020-04-28 17:35:28 +00:00
unset($headers['authorization']);
2020-04-15 23:09:27 +00:00
$headers['Authorization'] = $this->key;
}
$response = $client->request($method , $requestUrl , ['json'=> $body , 'form_params' => $formParams , 'headers' => $headers] );
return $response->getBody()->getContents();
}
}