PHP code example of smokills / laravel-http-client-default-options

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

    

smokills / laravel-http-client-default-options example snippets


$app->register(Smokills\Http\ServiceProvider::class);

// Somewhere in the code

/**
 * Since we have defined the base_uri as default option, we can simply make a
 * request using only the uri.
 */
$response = Http::get('/baz');

// Somewhere in the code

/**
 * The debug option and the basic auth will be used together the default options defined before.
 */
$response = Http::withOptions([
    'debug' => 'true'
])->withBasicAuth('username', 'password')->get('/baz');

// Remove all of the default options...
$response = Http::withoutDefaultOptions()->get('https://bar.com');

// Remove some of the global options
$response = Http::withoutDefaultOptions([
    'option', 'another-option'
])->get('https://bar.com');

// You can pass options to remove as arguments as well
$response = Http::withoutDefaultOptions('option', 'another-option')->get('https://bar.com');

// If you would like to remove deeply nested options, you may use the the dot notation syntax
$response = Http::withoutDefaultOptions('header.X-Some-Header')->get('https://bar.com');