mirror of
https://gitlab.com/izyim/prototypes/lumen-microservices/microservice-api-gateway.git
synced 2026-08-19 04:24:15 +00:00
40 lines
852 B
PHP
40 lines
852 B
PHP
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
namespace App\Traits;
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
trait RequestService
|
|
{
|
|
/**
|
|
* @param $method
|
|
* @param $requestUrl
|
|
* @param array $formParams
|
|
* @param array $headers
|
|
*
|
|
* @return string
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
*/
|
|
public function request($method, $requestUrl, $formParams = [], $headers = []) : string
|
|
{
|
|
$client = new Client([
|
|
'base_uri' => $this->baseUri
|
|
]);
|
|
|
|
if (isset($this->secret)) {
|
|
$headers['Authorization'] = $this->secret;
|
|
}
|
|
|
|
$response = $client->request($method, $requestUrl,
|
|
[
|
|
'form_params' => $formParams,
|
|
'headers' => $headers
|
|
]
|
|
);
|
|
|
|
return $response->getBody()->getContents();
|
|
}
|
|
}
|