PHP code example of coderatio / curler

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

    

coderatio / curler example snippets




$curler = new \Coderatio\Curler\Curler();
$curler->get('https://jsonplaceholder.typicode.com/todos');
$response = $curler->getResponse();



$data = [
  'title' => 'Sample post',
  'body' => 'This is a sample post',
  'userId' => 1
];

$curler = new \Coderatio\Curler\Curler();
$request = $curler->post('https://jsonplaceholder.typicode.com/posts', $data);
$response = $curler->getResponse();



$data = [
  'first_name' => 'John',
  'last_name' => 'Doe',
  'email' => '[email protected]'
];

$curler = new \Coderatio\Curler\Curler();
$request = $curler->postForm('https://example.com/store-user', $data);
$response = $curler->getResponse();


$response = $curler->getResponse()->asObject();

$response = $curler->getResponse()->asArray();


$curler = new \Coderatio\Curler\Curler();
$curler->appendRequestHeader('Content-Type', 'application/json');
$curler->post('https://jsonplaceholder.typicode.com/posts', $data);

$response = $curler->getResponse();



$curler = new \Coderatio\Curler\Curler();
$curler->appendRequestHeaders([
    'Content-Type' => 'application/xml',
    'x-access-token' => 'xxxxxxxxxx'
]);

$curler->post('https://jsonplaceholder.typicode.com/posts', $data);

$response = $curler->getResponse();


$curler->statuseCode;

$curler->addCurlOption('CURLOPT_PUT', true); // Single

// OR

$curler->addCurlOptions([
    'CURLOPT_PUT' => true,
    'CURLOPT_POSTFIELDS' => []
]);