PHP code example of pramod / api-consumer

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

    

pramod / api-consumer example snippets


$app->configure('api-consumer');

Api::consume('ebill')
    ->via('customers/pramodk_home/documents')
    ->with([
        'headers'=>[
                    'Authorization'=>'xx',
                    'Content-Type'=>'',
                    'Accept'=>''
                    ],
        'method'=>'POST',
        'version'=>'v1',
        'payload'=>[
            'name'=>'name is here'
        ]
    ])
    ->superChargedBy([
        'cache'=>[
            'ttl'=>20,
            'key_prefix'=>'documents'
        ]
    ])
    ->toArray();

    //add second param on your via method

    //for static uri eg, canvasenx.com.np/users
    return Api::consume('covid19api')
        ->via('summary', true)
        ->toCollection();

    //for dynamic uri you must add your uri payload with value as
    return Api::consume('covid19api')
        ->via('countryDayOneRoute', [
            'country'=>'nepal'
        ])
        ->toCollection();
        
    

    'covid19api'=>[
        'baseUri'=>'https://api.covid19api.com/',
        'custom_consumer' => [
            'Consumers/covid'
        ],
        'timeout'=>10
    ]
    

$app->middleware([
    Pramod\ApiConsumer\Middleware\LogRequestMiddleware::class
]);



return [
    'default'=>[
        'timeout'=>10,
        'ssl_verification'=>true,
        'method'=>"GET"
    ],
    'consumer' => [
        'graphqlTest'=>[
            'baseUri'=>'https://countries.trevorblades.com/',
            'timeout'=>60,
            // 'ssl_verification'=>false //my default its true
        ]
    ]
];


return Api::consume('graphqlTest')
            ->via('fcm/graphql')
            ->with([
                'graphQl'=>[
                    'query'=>'query{
                            continents{
                              code
                              name
                              countries{
                                code
                                name
                                native
                              }
                            }
                          }'
                    ]
            ])
sh
php artisan vendor:publish --provider="Pramod\ApiConsumer\ApiConsumerServiceProvider" --tag="config"
bash
cp vendor/pramod/ApiConsumer/config/api-consumer.php config/
 php
// Register Service Provider
 $this->app->register(ApiConsumerServiceProvider::class);