dansup/laravel-edmunds
Deprecated Laravel package for the Edmunds API. Note: Edmunds has retired its open APIs, so this package is no longer maintained or usable for new integrations.
Install via Composer:
composer require vendor/package-name
Register the package service provider in config/app.php (if not auto-discovered). The package now defaults to disabling Guzzle's http_errors flag (set to false), simplifying error handling by requiring manual HTTP status checks (e.g., response->getStatusCode() === 200). Test with a basic HTTP request:
use Vendor\Package\Facades\Client;
$response = Client::get('https://api.example.com/data');
if ($response->getStatusCode() !== 200) {
// Handle non-2xx responses explicitly
throw new \RuntimeException('API request failed');
}
Disable http_errors: The package now defaults to http_errors: false, meaning Guzzle will not throw exceptions for HTTP errors (e.g., 4xx/5xx). Use this to:
$response = Client::post('/submit', ['data' => $payload]);
if ($response->getStatusCode() >= 400) {
\Log::error('API Error:', ['status' => $response->getStatusCode(), 'body' => $response->getBody()->getContents()]);
}
Fallback to Exceptions (Optional):
Override the default config in config/package.php:
'guzzle' => [
'http_errors' => true, // Revert to throwing exceptions
],
Leverage the package’s client alongside Laravel’s Http facade for consistency:
// Package client (custom config)
$response = Client::withOptions(['timeout' => 30])->get('/data');
// Laravel HTTP client (default behavior)
$response = Http::timeout(30)->get('/data');
http_errors: false is now the default. Existing code relying on Guzzle exceptions for HTTP errors will break. Update error-handling logic to check $response->getStatusCode() explicitly.dd($response->getBody()->getContents()) to debug API payloads when http_errors is disabled.Client::withMiddleware(new \GuzzleHttp\Middleware::tap(function ($request, $next) {
\Log::debug('Request:', ['url' => (string) $request->getUri()]);
return $next($request)->then(function ($response) {
\Log::debug('Response:', ['status' => $response->getStatusCode()]);
return $response;
});
}));
Client::macro('safeGet', function ($url) {
$response = $this->get($url);
if ($response->getStatusCode() !== 200) {
throw new \Vendor\Package\Exceptions\ApiException($response);
}
return $response;
});
php artisan vendor:publish --tag=package-config
Then modify config/package.php to re-enable http_errors if needed.Disabling http_errors avoids exception overhead but requires manual status checks. For high-throughput APIs, consider:
$response = Client::get('/data')->getBody()->getContents(); // Skip status checks if 200 is guaranteed
How can I help you explore Laravel packages today?