PHP code example of jdwx / http-client

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

    

jdwx / http-client example snippets


use JDWX\HttpClient\Response;

$client = new \Some\Http\Client();
$response = $client->request('GET', 'https://api.example.com/resource');
$httpResponse = new Response($response);
if (!$httpResponse->isSuccess()) {
    $statusCode = $httpResponse->getStatusCode();
    echo "Error: HTTP Status {$statusCode}\n";
    exit(1);
}
if (!$httpResponse->isContentType('application/json')) {
    echo "Error: Expected JSON response, got: " . $httpResponse->getContentType() . "\n";
    exit(1);
}
$data = json_decode( $httpResponse->body(), true );
var_dump( $data );