PHP code example of grixu / api-client

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

    

grixu / api-client example snippets


use Grixu\ApiClient\Config\JsonApiConfig;
use Grixu\ApiClient\Data\PaginatedData;
use Grixu\ApiClient\Data\StraightKeyParser;

$config =  new JsonApiConfig(
            baseUrl: 'http://rywal.com.pl',
            responseDataClass: PaginatedData::class,
            responseParserClass: StraightKeyParser::class,
            authType: 'oAuth2',  // or you can use enum: AuthType::OAUTH2()
            authUrl: 'http://rywal.com.pl',
            authData: ['key', 'secret'],
            paginationParam: 'page',
            filters: ['list', 'of', 'param', 'names', 'that', 'could', 'be', 'used', 'as', 'filters'],
            

use Grixu\ApiClient\JsonApiFetcher;

$fetcher = new JsonApiFetcher($config, '/api/path');

// in every example you could pass multiple values
$fetcher->compose()->addFilter('filter_name', 'filter_value_1');
$fetcher->compose()->addInclude('ove to next page by hand
$fetcher->compose()->nextPage();

$fetcher->fetch();
$parsedCollection = $parser->parse(DtoClass::class);
dotenv
API_ERROR_LOGGING=true
API_ERROR_LOG_CHANNEL="api-client"