1. Go to this page and download the library: Download astrotomic/laravel-guzzle 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/ */
astrotomic / laravel-guzzle example snippets
use Astrotomic\LaravelGuzzle\Facades\Guzzle;
use Psr\Http\Message\ResponseInterface;
/** @var ResponseInterface $response */
$response = Guzzle::client('jsonplaceholder')->get('posts/1');
$response->getStatusCode(); // 200
use Astrotomic\LaravelGuzzle\Facades\Guzzle;
use Illuminate\Support\ServiceProvider;
use GuzzleHttp\RequestOptions;
class HttpServiceProvider extends ServiceProvider
{
public function boot(): void
{
Guzzle::register('jsonplaceholder', [
'base_uri' => 'https://jsonplaceholder.typicode.com',
RequestOptions::TIMEOUT => 3,
]);
}
}
use Astrotomic\LaravelGuzzle\Facades\Guzzle;
use GuzzleHttp\Client;
use Illuminate\Contracts\Container\Container;
Guzzle::extend('astrotomic', static function (Container $app, ?array $config): Client {
return new Client(array_merge([
'base_uri' => 'https://astrotomic.info',
], $config));
});