Pros:
GuzzleHttp via PSR18 adapters like php-http/guzzle9-adapter), enabling middleware injection (e.g., auth, retries) and request/response transformation.symfony/serializer (already used in Laravel for JSON handling) and symfony/yaml, minimizing dependency bloat.Cons:
zircote/swagger-php) or manual migration.Illuminate\Bus\Queueable).HttpException hierarchy, needing custom mapping.Http facade (Guzzle under the hood) or standalone PSR18 clients (e.g., php-http/client-implementation).Kernel classes) to intercept requests/responses:
$client->withMiddleware([
new AuthMiddleware(),
new RetryMiddleware(),
]);
$this->app->singleton(Generated\Client::class, fn () => new Generated\Client(
new Psr17Factory(),
new Psr17Factory(),
new GuzzleHttpClient(),
));
composer script or custom Artisan command to regenerate clients post-schema updates. Example:
"scripts": {
"post-update-cmd": "jane openapi:generate api-spec.yaml --output=src/Generated",
"api:generate": "jane openapi:generate api-spec.yaml --output=src/Generated"
}
openapi-linter or spectral.nikic/php-parser (~1MB) and symfony/serializer (~2MB), increasing vendor size by ~5MB.symfony/serializer).CONTRIBUTING.md.blackfire.io; cache responses at the Laravel level (e.g., Cache::remember()).Illuminate\Support\Facades or Illuminate/Contracts natively.class LaravelApiClient {
public function __construct(private Generated\Client $client) {}
public function getUsers() {
return $this->client->get('/users')->toArray();
}
}
zircote/swagger-php) for future-proofing? If hybrid support is needed, evaluate openapi-client-php.pre-push).spec/*.yaml changes).php artisan api:generate command.Generated\Client\Exception\ApiException) map to Laravel’s HttpException hierarchy? Example:
try {
$response = $client->someEndpoint();
} catch (ApiException $e) {
throw new HttpException($e->getStatusCode(), $e->getMessage());
}
php-http/mock-client).pact or vcr).php-openapi/client-generator (OpenAPI 3.x).swagger-php/swagger-php (more customizable but heavier).openapi-generator CLI) for more control.Http facade (Guzzle under the hood) with a PSR18 adapter:
use Illuminate\Support\Facades\Http;
use Generated\Client\Client;
use PHPHttp\Client\Common\Plugin\PluginInterface;
$client = new Client(
new Psr17Factory(),
new Psr17Factory(),
new GuzzleHttpClient(new PluginStack([
new RetryPlugin(),
])),
);
php-http/guzzle9-adapter).$this->app->singleton(Generated\Client::class, fn () => new Generated\Client(
app(Psr17Factory::class),
app(Psr17Factory::class),
app(GuzzleHttpClient::class),
));
$client->withMiddleware([
new AuthMiddleware(),
new LogMiddleware(),
]);
file, redis) for performance:
$serializer = new Serializer([
new ObjectNormalizer(),
], [new JsonEncoder()]);
Cache::remember('serializer', now()->addHours(1), fn () => $serializer);
spatie/laravel-yaml-driver; exclude via Composer:
"replace": {
"symfony/yaml": "*"
}
How can I help you explore Laravel packages today?