guzzlehttp/command
Build higher-level web service clients on top of Guzzle by modeling operations as Commands and responses as Results. Includes a generic ServiceClient plus command middleware to map commands to PSR-7 requests and responses to structured results.
Illuminate\Http\Client uses Guzzle under the hood).Command/Result pattern maps naturally to Laravel’s repository pattern or service layer, where business logic can be encapsulated in domain-specific commands.Http facade or Client class. For example:
use GuzzleHttp\Command\ServiceClient;
use Illuminate\Support\Facades\Http;
$guzzleClient = new ServiceClient(
Http::client()->handlerStack, // Reuse Laravel's Guzzle client
// ... transformers
);
ClientInterface) aligns with Laravel’s service container, allowing for easy binding:
$this->app->bind(ServiceClientInterface::class, function ($app) {
return new ServiceClient(
$app->make(GuzzleHttp\ClientInterface::class),
// ...
);
});
Command/Result structure can be used to generate Laravel API resources or Eloquent models dynamically, reducing manual mapping logic.executeAll) could impact memory usage if not managed (e.g., unbounded concurrency).HttpClientException) must be mapped to CommandException types. Custom middleware may need to rethrow exceptions in a Laravel-compatible format.web, api) interact with command middleware?executeAll? Should it default to Laravel’s queue worker count?CommandInterface and ResultInterface? The package’s abstractions may require custom test doubles.Http facade with ServiceClient for API-heavy applications.executeAsync) to background workers.command.executed) from command middleware for observability.config/http.php) as the underlying transport.ServiceClient alongside Laravel’s Http facade.Http::post() calls with command-based interactions.ServiceClient and expose it via a facade:
// app/Providers/CommandServiceProvider.php
public function register()
{
$this->app->singleton(ServiceClientInterface::class, function ($app) {
return new ServiceClient(
$app->make(GuzzleHttp\ClientInterface::class),
// Command → Request transformer
// Response → Result transformer
);
});
}
guzzlehttp/retry), ensure they’re compatible with the command layer.Psr\Http\Message\ResponseInterface handlers) can coexist with command middleware but may require adapters.ServiceClient to Laravel’s container.guzzlehttp/circuit-breaker).guzzlehttp/command to a specific minor version (e.g., ^1.4) to avoid breaking changes.docs/api/commands.md) to aid future developers.php artisan tag:listen) to track middleware changes.$client->getHandlerStack()->push(function ($handler) {
return function ($command) use ($handler) {
Log::debug('Executing command', ['name' => $command->getName(), 'args' => $command->toArray()]);
return $handler($command);
};
});
CommandException to Laravel’s ProblemException or custom exceptions for consistent error responses.public function render($request, Throwable $exception)
{
if ($exception instanceof CommandException) {
return response()->json(['error' => $exception->getMessage()], 400);
}
}
zircote/swagger-php.@http) and validation rules for each command.executeAll based on Laravel’s queue workers or API rate limits (e.g., concurrency: 5).How can I help you explore Laravel packages today?