PHP code example of kielabokkie / laravel-guzzle-api-service

1. Go to this page and download the library: Download kielabokkie/laravel-guzzle-api-service 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/ */

    

kielabokkie / laravel-guzzle-api-service example snippets


return [
    /*
     * Enable logging of request and responses to storage/logs/api-service.log
     */
    'logging_enabled' => env('API_SERVICE_LOGGING_ENABLED', false),

    /*
     * The namespace where your API Service classes are created under.
     * This will be appended to your base namespace. So the config below
     * will create a class under App\Support\Services.
     */
    'namespace' => 'Support\Services'
];



namespace App\Support\Services;

use Kielabokkie\GuzzleApiService\ApiClient;

class HttpBinService extends ApiClient
{
    protected $baseUrl = 'https://httpbin.org';

    public function __construct()
    {
        $this->setClient();
    }
}

public function yourGetRequest()
{
    $response = $this->get('/get'));

    return json_decode($response->getBody()->getContents());
}

protected function defaultHeaders()
{
    return [
        'Authorization' => 'Bearer abcdef123456',
    ];
}

protected function defaultQueryParams()
{
    return [
        'token' => 'your-token'
    ];
}
bash
php artisan vendor:publish --provider="Kielabokkie\GuzzleApiService\GuzzleApiServiceProvider"
bash
php artisan make:api-service HttpBinService