PHP code example of jdwx / json-api-client

1. Go to this page and download the library: Download jdwx/json-api-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 / json-api-client example snippets


$client = JDWX\JsonApiClient\HttpClient::withGuzzle( 'https://api.example.com' );
$rsp = $client->request( 'GET', '/v1/resource' );
if ( ! $rsp->isSuccess() ) {
    $uStatus = $rsp->status();
    echo "{$uStatus} Error: ", $rsp->body(), "\n";
    exit( 1 );
}
if ( ! $rsp->isJson() ) {
    $stContentType = $rsp->getOneHeader( 'content-type' ) ?? 'none';
    echo "Error: Expected JSON content-type, got: {$stContentType}\n";
    exit( 1 );
}
$data = $rsp->json();
var_dump( $data );