PHP code example of devawal / restful-curl

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

    

devawal / restful-curl example snippets


object|array RestCurl::get(string $url, array $parameters, boolean $json_post, array $header, boolean $object)



use RestfullCurl\RestCurl;

// Get request
$response = RestCurl::get('https://jsonplaceholder.typicode.com/posts');

// Post request
$response = RestCurl::post('https://jsonplaceholder.typicode.com/posts');

// Post request with parameters and header
$param = array(
                'grant_type'=>'password', 
                'client_secret'=>'s5df5d6f6d6f', 
              );
$header = array('Accept: application/json', 'Authorization: Bearer df98df665df6d8f8');
$response = RestCurl::post('https://jsonplaceholder.typicode.com/posts', $parameters, true, $header);

// Put request
$response = RestCurl::put('https://jsonplaceholder.typicode.com/posts/1');

// Patch request
$response = RestCurl::patch('https://jsonplaceholder.typicode.com/posts/1');

// Delete request
$response = RestCurl::delete('https://jsonplaceholder.typicode.com/posts/1');