cURL Get 👇🏼

<?php
    $curl = curl_init();
    // Initialize a cURL session

    $url = "https:/reqres.in/api/users/2";
    //  The URL to fetch.
    
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    // To stop cURL for verifying the SSL certificate.

    curl_setopt($curl, CURLOPT_URL , $url);
    // The URL to fetch.

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
   // To return the transfer as a string of the return value of curl_exec() instead of outputting it directly.
   $response = curl_exec($curl);
   // To Execute curl

   $err = curl_error($curl);
   // Returns a error message if any error.

      if ($err)
         echo $err;
            
      else    
        echo $response;  // Showing JSON data from API. 

           curl_close($curl);
           // Close a cURL session

           $arr = json_decode($response, true);
           // Decode $response to array.

           var_dump($arr);
           // To Preview array.
?>

<hr>

<h2> <?php echo $arr['data']['first_name']; ?> </h2> 
<h2> <?php echo $arr['data']['last_name']; ?>  </h2> 
<h2> <?php echo $arr['data']['email']; ?>      </h2> 
<img src="<?php echo $arr['data']['avatar']; ?>">

cURL POST 👇🏼

<?php

    $curl = curl_init();

    $url = "https://reqres.in/api/users";

    $upload = array(
        "name" => "Lost Variables",
        "city" => "Vormir"
    );

    $data = http_build_query($upload);

    curl_setopt_array($curl , [
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_URL => $url,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $data,
    CURLOPT_RETURNTRANSFER => true
    ]);

    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    if ($err)
        echo $err;
    
    else    
        echo $response;

    curl_close($curl);
    
    $arr = json_decode($response, true);
    var_dump($arr);

    echo "<h1>" . $arr['name'];

?>

cURL PUT 👇🏼

<?php

    $curl = curl_init();

    $url = "https://reqres.in/api/users/2";

    $upload = array(
        "name" => "Lost Variables",
        "city" => "Vormir"
    );

    $data = http_build_query($upload);

    curl_setopt_array($curl , [
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_URL => $url,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS => $data,
    CURLOPT_RETURNTRANSFER => true
    ]);

    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    if ($err)
        echo $err;
    
    else    
        echo $response;

    curl_close($curl);
    
    $arr = json_decode($response, true);
    var_dump($arr);

    echo "<h1>" . $arr['name'];

?>

Save Response to text file. 👇🏼

<?php
    $curl = curl_init();

    $url = "https://reqres.in/api/users?page=2";

    $fl = fopen('savehere.txt', 'w');
    curl_setopt_array($curl , [
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_URL => $url,
    CURLOPT_FILE => $fl
    // CURLOPT_RETURNTRANSFER => true
    ]);

    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    if ($err)
        echo $err;
    
    else    
        echo $response;

    curl_close($curl);
    
    // $arr = json_decode($response, true);
    // var_dump($arr);

    // echo "<h1>" . $arr['name'];

?>

API Website https://reqres.in