PHP code example of lowem / easy-curl

1. Go to this page and download the library: Download lowem/easy-curl 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/ */

    

lowem / easy-curl example snippets


composer 


use Lowem\EasyCurl\EasyCurl;

        [
          "Content-Type: application/json",
          "Accept: application/json"
        ]
        

  $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts");
  try {
    $test->get();
  } catch (HTTPRequestException $e) {
    echo $e->getCustomMessage();
  }
  print_r($test->getExecMessage());

  $test->close();
  

        [
          "title" => "foo",
          "body" => "bar",
          "userId" => 1
        ]
        

        [
          "Content-Type: application/json",
          "Accept: application/json"
        ]
        

  $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts");
  try {
    $data = [
      "title" => "foo",
      "body" => "bar",
      "userId" => 1
    ];
    $test->post(json_encode($data), [
      "Content-type: application/json; charset=UTF-8",
    ]);
  } catch (HTTPRequestException $e) {
    echo $e->getCustomMessage();
  }
  print_r($test->getExecMessage());
  
  $test->close();
  

        [
          "id" => 1,
          "title" => "foo",
          "body" => "bar",
          "userId" => 1
        ]
        

        [
          "Content-Type: application/json",
          "Accept: application/json"
        ]
        

  $test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1");
  try {
    $data = [
      "id" => 1,
      "title" => "foo",
      "body" => "bar",
      "userId" => 1
    ];
    $test->put(json_encode($data), [
      "Content-type: application/json; charset=UTF-8",
    ]);
  } catch (HTTPRequestException $e) {
    echo $e->getCustomMessage();
  }
  print_r($test->getExecMessage());
  
  $test->close();
  

$test = new EasyCurl("https://jsonplaceholder.typicode.com/posts/1");
try {
  $test->delete();
} catch (HTTPRequestException $e) {
  echo $e->getCustomMessage();
}
print_r($test->getExecMessage());

$test->close();