Stephen Ginn at Crema Design Studio
You can install the package via composer:
composer config repositories.crema/fetcher git https://github.com/cremadesign/fetcher
composer require crema/fetcher:@dev
Add this code to your PHP file:
require_once '../vendor/autoload.php';
use Crema\CurlRequest;
$curl = new CurlRequest();
header('Content-Type: application/json');
$url = "https://dummyjson.com/products/1";
$response = $curl->request($type, $url, $payload, $headers);
echo json_encode($response->json(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Shortcut to $curl->request("GET")
$response = $curl->get($url);
echo json_encode($response->json(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Shortcut to $curl->request("POST")
$response = $curl->post($url, $data);
echo json_encode($response->json(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Merges request headers into the current headers
$curl->addRequestHeaders([
'X-Custom' => 'Lorem Ipsum'
]);
$headers = $curl->getRequestHeaders();
echo json_encode($headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
This feature is useful for removing the default "Content-Type" header, so that the request body isn't encoded to JSON.
$headers = $curl->removeRequestHeaders();
echo json_encode($headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Add this code to your PHP file:
require_once '../vendor/autoload.php';
use Crema\Fetcher;
$fetcher = new Fetcher();
$response = $fetcher->request($url);
header('Content-Type: application/json');
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);