PHP code example of saraf / async-request

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

    

saraf / async-request example snippets


// initialize basic class
$api = new \Saraf\AsyncRequestJson()
$api->setConfig([
    "baseURL" => "https://jsonplaceholder.typicode.com"
]);

// It will return Promise
$api->post("/todos", [
    'title' => 'learn async-request lib',
    'isDone' => false
])->then(function ($response) {
    // $response contains result, status code, headers and body of that request      
});

$api->setResponseHandler(\Saraf\ResponseHandlers\HandlerEnum::Json);