for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace quideroli\httpRequest;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
class Request
{
public function __construct($url, $query = NULL, $header = [], $body = "")
$this->url = $url;
url
$this->config = [
config
"headers" => $header,
"query" => $query,
"body" => !empty($body) ? json_encode($body) : "{}"
];
}
public function get()
try {
$send = (new Client())->get($this->url, $this->config);
return $send->getBody()->getContents();
}catch(ClientException $e){
$this->error = $e;
error
return false;
public function post()
$send = (new Client())->post($this->url, $this->config);
public function put()
$send = (new Client())->put($this->url, $this->config);
public function delete()
$send = (new Client())->delete($this->url, $this->config);
public function fail($show=true)
if($show==true){
header('Cache-Control: no-cache, must-revalidate');
header('Content-Type: application/json');
http_response_code($this->error->getCode());
echo $this->error->getResponse()->getBody();
exit();
exit
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.
}else{
return $this->error->getResponse()->getBody();