Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Guzzle Bundle Laravel Package

caciobanu/guzzle-bundle

View on GitHub
Deep Wiki
Context7

Guzzle Symfony Bundle

This is a Symfony bundle that integrates Guzzle for easier use.

Build Status Code Coverage

Installation

You can use Composer to install the extension to your project:

composer require caciobanu/guzzle-bundle

Then create a minimal config file caciobanu_guzzle.yml in config/packages/:

caciobanu_guzzle:
    clients:
        google:
            base_uri: 'https://google.com'

A complete configuration looks like:

caciobanu_guzzle:
    clients:
        google:
            client_class: 'Your\Client'    # You must extend 'GuzzleHttp\Client' which is the default value.
            base_uri: 'https://google.com'
            logging: true                  # Enable logging. Default value: false.
            options:                       # See http://docs.guzzlephp.org/en/stable/request-options.html for all available options.
                timeout: 30
                headers:
                    'User-Agent': 'Test Agent'

Usage

Using services in controller:

/** @var \GuzzleHttp\Client $client */
$client   = $this->get('caciobanu_guzzle.client.google');
$response = $client->get('/');

Adding Guzzle middleware

Adding a Guzzle middleware is a two step process:

  1. Create a new class:
<?php

namespace App\Guzzle\Middleware;

use Caciobanu\Symfony\GuzzleBundle\Middleware\BeforeRequestMiddlewareInterface;
use Psr\Http\Message\RequestInterface;

class MyMiddleware implements BeforeRequestMiddlewareInterface
{
    public function __invoke(RequestInterface $request): RequestInterface
    {
        // Do something with the request
        return $request;
    }
}
  1. Create a Symfony service like so:
# config/services.yaml
services:
    App\Guzzle\Middleware\MyMiddleware:
        tags:
            - { name: 'caciobanu_guzzle.middleware', client: 'google' }

There are three middleware interfaces that can be implemented:

  • Caciobanu\Symfony\GuzzleBundle\Middleware\BeforeRequestMiddlewareInterface - marks middleware to be called before sending the request
  • Caciobanu\Symfony\GuzzleBundle\Middleware\AfterResponseMiddlewareInterface - marks middleware to be called after the response is received
  • Caciobanu\Symfony\GuzzleBundle\Middleware\OnErrorMiddlewareInterface - marks middleware to be called when an errors occurs
  • Caciobanu\Symfony\GuzzleBundle\Middleware\RetryMiddlewareInterface - offers the possibility to retry requests

Credits

This library is developed by Catalin Ciobanu.

License

license

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator