How To Use • Download • License
# Clone this repository
$ git clone https://github.com/hstanleycrow/EasyPHPcURLRequest/
# install libraries
$ composer update
# or install using composer
$ composer require hstanleycrow/easyphpcurlrequest
$url = "https://reqres.in/api/users";
$postData = array(
'name' => 'John Doe',
'job' => 'Web Developer'
);
$request = new CurlRequest($url);
$request->setPost(true);
$request->setPostData(json_encode($postData));
$request->setHttpHeader([
'Content-Type: application/json'
]);
$request->execute();
if ($request->isSuccessful()) :
$response = $request->getResult();
$response_data = json_decode($response, true);
var_dump($response_data);
else :
echo "Error";
endif;
#example 2: get request
$url = 'https://jsonplaceholder.typicode.com/posts';
$request = new CurlRequest($url);
$request->setPost(false);
$request->setHttpHeader([
'Content-Type: application/json'
]);
$request->execute();
if ($request->isSuccessful()) :
$response = $request->getResult();
$response_data = json_decode($response, true);
var_dump($response_data);
else :
echo "Error";
endif;
You can download the latest version here.
I have tested this class only in this PHP versions. So, if you have an older version and do not work, let me know.
PHP Version |
---|
PHP 8.0 |
PHP 8.1 |
PHP 8.2 |
MIT
www.hablemosdeseo.net · GitHub @hstanleycrow · Twitter @harold_crow