Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function guzzleRequest($url, $method, $params = []) {
- $client = new Client();
- $params = $method === 'POST' ? ['body' => json_encode($params)] : ['query' => $params];
- $response = $client->request($method, $url,
- [
- 'headers' => [
- 'Content-Type' => 'application/json',
- 'Accept' => 'application/json',
- ],
- 'http_errors' => false,
- ] + $params);
- $res = json_decode((string)$response->getBody(), true);
- if ($response->getStatusCode() === 200) {
- // dd($res);
- return $res ?? true;
- } else if ($res['error'] === 404) {
- throw new ApiException($res['error'], 404);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement