PHP code example of hstanleycrow / easyphpcurlrequest

1. Go to this page and download the library: Download hstanleycrow/easyphpcurlrequest library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hstanleycrow / easyphpcurlrequest example snippets



$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;