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

Guzzle7 Adapter Laravel Package

php-http/guzzle7-adapter

PSR-7/PSR-18 adapter for Guzzle 7 used by HTTPlug. Lets libraries using PHP-HTTP talk through Guzzle 7 with a standard client interface, including synchronous requests and integration-friendly configuration for modern PHP projects.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require php-http/guzzle7-adapter. This package provides a PSR-18 compliant HTTP client wrapper for Guzzle 7, allowing interoperability with libraries expecting PSR-18 clients (e.g., Laravel’s http() client, Symfony HttpClientBridge, or third-party SDKs). Start by resolving the client via the container: app(\Psr\Http\Client\ClientInterface::class)—it will automatically resolve to the Guzzle 7 adapter. Use it like any PSR-18 client: $response = $client->sendRequest($request); (where $request is a PSR-7 request).

Implementation Patterns

  • Laravel Integration: In Laravel, register Guzzle7Adapter as the default PSR-18 client by adding Http\Adapter\Guzzle7\Client in config/app.php’s providers (for older Laravel) or via service provider binding in AppServiceProvider. Alternatively, rely on Laravel’s built-in http() helper (which uses this adapter under the hood if configured).
  • Decoupled HTTP Usage: Inject \Psr\Http\Client\ClientInterface into services to avoid direct Guzzle dependencies, enabling easier testing with PSR-18 mocks.
  • Middleware Reuse: Leverage existing Guzzle middleware (e.g., retry, logging) by customizing the underlying Guzzle client configuration before instantiating the adapter—though note the adapter itself doesn’t expose middleware setup; configuration happens in the wrapped GuzzleHttp\Client.

Gotchas and Tips

  • No Direct Guzzle API Access: This package only implements PSR-18/7. If you need Guzzle-specific features (e.g., requestAsync() with custom options, handlers, or request builders), you must resolve the underlying GuzzleHttp\Client separately or maintain a separate Guzzle dependency.
  • Middleware Limitations: Unlike injecting a raw Guzzle client, you cannot directly attach middleware to the adapter. To customize behavior (e.g., add authorization headers globally), configure the underlying Guzzle client before wrapping it—or use Laravel’s http() middleware stack if using Laravel.
  • Testing Tip: When mocking the PSR-18 client for unit tests, ensure your mocks return valid PSR-7/17 objects (e.g., Mockery::mock(\Psr\Http\Client\ClientInterface::class) with proper return types). Laravel’s Http::preventStrayRequests() works seamlessly with this setup.
  • Dependency Chain: If you’re using other HTTPlug adapters (e.g., php-http/curl-client), ensure only one PSR-18 client binding exists to avoid ambiguity in dependency injection.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests