<?php
namespace App\Services;
use GuzzleHttp\Client;
class HttpService
{
protected $client;
public function __construct(Client $client)
{
$this->client = $client;
}
public function get(string $url, array $params = [], array $options = [])
{
$fullurl = $url . '?' . http_build_query($params);
return $this->client->get($fullurl, $options)->getBody()->getContents();
}
public function post(string $url, array $params = [], array $options = [])
{
if (! empty($params)) {
$options['json'] = $params;
}
return $this->client->post($url, $options)->getBody()->getContents();
}
}