PHP Classes

File: apps/ApiGateway/app/Traits/ConsumeExternalService.php

Recommend this page to a friend!
  Classes of mohammad anzawi   PHP Hotel Booking Available   apps/ApiGateway/app/Traits/ConsumeExternalService.php   Download  
File: apps/ApiGateway/app/Traits/ConsumeExternalService.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Hotel Booking Available
Search for hotels that are available for booking
Author: By
Last change:
Date: 2 years ago
Size: 911 bytes
 

Contents

Class file image Download
<?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, $query = [], $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,
           
'query' => $query
       
]);

        return
$response->getBody()->getContents();
    }
}