Skip to content

Instantly share code, notes, and snippets.

@anoriar
Created July 3, 2019 22:27
Show Gist options
  • Save anoriar/7cced46b20145f2974f40585c2bcecdd to your computer and use it in GitHub Desktop.
Save anoriar/7cced46b20145f2974f40585c2bcecdd to your computer and use it in GitHub Desktop.
guzzle request
namespace Shell\Service;
use GuzzleHttp\Exception\ClientException;
use Psr\Log\LoggerInterface;
class DeliveryService
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function getDeliveryServices(){
$client = new \GuzzleHttp\Client();
try {
$res = $client->request('GET', 'https://api.saferoute.ru/api/hjo46n_zqac8hj6bemnmbli_rbpphh6b/list/city.json', ['id' => 1]);
} catch (ClientException $e) {
$res = $e->getResponse();
// логируем ошибку
}
$arData = json_decode($res->getBody()->getContents());
if ($res->getStatusCode() == 200) {
// логируем успешность запроса
}
$result = [
'status' => $res->getStatusCode(),
'message' => null,
'data' => $arData
];
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment