PHP code example of bera / request

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

    

bera / request example snippets




use Bera\Request\Request;

$url = 'https://jsonplaceholder.typicode.com/posts';
$request = new Request('GET',$url);
print_r($request->response());
print_r($request->responseAsArray()); // for response as an array



use Bera\Request\Request;

$url = 'https://jsonplaceholder.typicode.com/posts';
$payload = array(
    'title' => 'foo',
    'body' => 'bar',
    'userId' => 1
);
$request = new Request('POST',$url);
$request->attachPayLoad($payload);
print_r($request->responseAsArray()); // for response as an array