PHP code example of hraw / httpclient

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

    

hraw / httpclient example snippets




use Curl\HttpClient;

$response = HttpClient::get('https://jsonplaceholder.typicode.com/todos')->send();



//Get the data returned by api
$response->data();

//Get status code
$response->statusCode();

//Check if response received is success response or not
$response->success();

//Get all the properties returned in response
$response->properties();

HttpClient::get($url)
            ->timeout(60)
            ->headers([
                'Content-Type : application/json',
                'Authorization : Bearer {token}'
            ])
            ->send();

HttpClient::post($url, $data)->send();