Weave Code
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

Httpclient Buzz Laravel Package

digital-link/httpclient-buzz

Laravel-friendly integration for the Buzz HTTP client, providing a simple way to send HTTP requests and handle responses within your app or package. Useful for lightweight API calls, configurable clients, and swapping transports with minimal setup.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require digital-link/httpclient-buzz
    

    Register the service provider in config/app.php:

    'providers' => [
        // ...
        DigitalLink\HttpClient\BuzzServiceProvider::class,
    ],
    
  2. Basic Usage Resolve the client via Laravel’s IoC container:

    $client = app('buzz.client');
    

    Or inject it into a controller/service:

    public function __construct(\Buzz\Client\ClientInterface $client) {
        $this->client = $client;
    }
    
  3. First HTTP Request Use the client to make a GET request:

    $response = $this->client->get('https://api.example.com/data');
    $content = $response->getContent();
    

Implementation Patterns

Common Workflows

  1. Request Customization Configure headers, timeouts, or authentication:

    $request = $this->client->get('https://api.example.com/data', [
        'headers' => ['Authorization' => 'Bearer token123'],
        'timeout' => 10,
    ]);
    
  2. Handling Responses Parse JSON responses or check status codes:

    $response = $this->client->post('https://api.example.com/submit', [
        'body' => json_encode(['key' => 'value']),
        'headers' => ['Content-Type' => 'application/json'],
    ]);
    
    if ($response->getStatusCode() === 200) {
        $data = json_decode($response->getContent(), true);
    }
    
  3. Middleware Integration Attach middleware (e.g., logging, retries) via the Buzz client:

    $client = new \Buzz\Client\Client([
        'plugins' => [
            new \Buzz\Plugin\LoggerPlugin(),
            new \Buzz\Plugin\RetryPlugin(),
        ],
    ]);
    app()->bind('buzz.client', function () use ($client) {
        return $client;
    });
    
  4. Dependency Injection Bind the client to interfaces for better testability:

    $this->app->bind(
        \Buzz\Client\ClientInterface::class,
        \DigitalLink\HttpClient\BuzzClient::class
    );
    

Gotchas and Tips

Pitfalls

  1. Deprecated Package

    • Last release in 2014; ensure compatibility with Laravel’s current PHP/Buzz versions.
    • May require manual dependency resolution (e.g., buzz/buzz v0.10+).
  2. No Built-in Laravel Facade

    • No Http::buzz() facade; use app('buzz.client') directly or create a custom facade.
  3. Response Handling Quirks

    • getContent() returns raw strings; decode JSON manually:
      json_decode($response->getContent(), true);
      
    • Status codes are integers (e.g., 200), not Response objects.
  4. Configuration Overrides

    • The package doesn’t expose a config file; configure the Buzz\Client directly in the service provider:
      $this->app->singleton('buzz.client', function () {
          return new \Buzz\Client\Client([
              'base_url' => 'https://api.example.com',
              'timeout' => 30,
          ]);
      });
      

Debugging Tips

  1. Enable Buzz Logging Attach a LoggerPlugin to inspect requests/responses:

    $client->getPlugin('logger')->setOutput(fopen('php://stdout', 'w'));
    
  2. Validate Headers Ensure headers are formatted as key-value arrays:

    // Correct:
    ['headers' => ['Accept' => 'application/json']]
    // Incorrect (will fail silently):
    ['headers' => 'application/json']
    
  3. Timeout Handling Set timeouts explicitly to avoid hanging:

    $client->setTimeout(15); // Global timeout (seconds)
    

Extension Points

  1. Custom Request Factories Extend the client to wrap requests in Laravel’s Illuminate\Http\Request:

    $request = new \Illuminate\Http\Request([
        'url' => 'https://api.example.com',
        'method' => 'POST',
        'headers' => ['X-Custom' => 'Header'],
    ]);
    $response = $this->client->send($request);
    
  2. Response Decorators Create a decorator to add Laravel-specific methods:

    class LaravelBuzzResponse implements \Buzz\Client\ResponseInterface {
        protected $response;
    
        public function __construct(\Buzz\Client\ResponseInterface $response) {
            $this->response = $response;
        }
    
        public function json() {
            return json_decode($this->response->getContent(), true);
        }
    }
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky