Since this is a Symfony bundle, Laravel integration requires Bridge or manual adaptation. For a quick test:
Install via Composer (adjust for Laravel):
composer require arnulfosolis/apihistogram @dev
Note: Laravel 5.5+ uses auto-discovery; older versions may need manual registration.
Publish Config (Symfony-style):
php artisan vendor:publish --provider="ApiHistogram\ApiHistogramBundle\ApiHistogramBundle"
Check config/apihistogram.php for Laravel-compatible config.
Define API Targets in config/apihistogram.php:
'sites' => [
'weather_api' => [
'url' => 'https://api.weather.com/v1/forecast',
'method' => 'GET',
'frequency' => 3600, // Update every hour (seconds)
],
],
Run the Command (Symfony CLI):
php artisan apihistogram:update
For Laravel, create a custom Artisan command to wrap the Symfony command.
// app/Console/Kernel.php
protected function schedule(Schedule $schedule) {
$schedule->command('apihistogram:update')->hourly();
}
$histories = ApiHistogram\ApiHistogramBundle\Entity\ApiHistogram::all();
Define Targets in config/apihistogram.php:
'sites' => [
'github_trending' => [
'url' => 'https://api.github.com/search/repositories?q=laravel',
'method' => 'GET',
'headers' => ['Authorization' => 'token YOUR_TOKEN'],
'frequency' => 86400, // Daily
],
],
Extend for Laravel:
// app/Providers/ApiHistogramServiceProvider.php
public function boot() {
$this->app->register(\ApiHistogram\ApiHistogramBundle\ApiHistogramBundle::class);
}
config/app.php.Customize Storage:
ApiHistogram\Entity\ApiHistogram) to add Laravel-specific fields (e.g., created_at timestamp).Integrate with Events:
// Listen to API response events (if bundle supports hooks)
Event::listen('apihistogram.response', function ($response, $target) {
Log::info("Stored response for {$target['url']}", ['response' => $response]);
});
Batch Updates: Use Laravel’s queue system to process multiple API calls asynchronously:
// app/Console/Commands/UpdateApiHistograms.php
public function handle() {
foreach (config('apihistogram.sites') as $target) {
UpdateApiHistogramJob::dispatch($target);
}
}
Rate Limiting: Implement middleware to throttle API calls:
// app/Http/Middleware/ThrottleApiCalls.php
public function handle($request, Closure $next) {
$key = $request->ip().'|'.$request->path();
if (cache()->has($key)) {
return response('Rate limit exceeded', 429);
}
cache()->put($key, true, now()->addSeconds(60));
return $next($request);
}
Symfony Dependency Mismatch:
laravel-doctrine/orm) or fork the bundle to replace Doctrine with Eloquent.Asynchronous Quirks:
sync queues for testing:
php artisan queue:work --once --env=local
Config Overrides:
config/caching may ignore published bundle configs. Fix: Manually merge configs in bootstrap/app.php:
$app->configure('apihistogram');
Database Schema:
api_histograms table:
Schema::table('api_histograms', function (Blueprint $table) {
$table->timestamps();
});
Command Output:
php artisan apihistogram:update --verbose
HTTP Errors:
// Override the HTTP client in the bundle’s service config
'guzzle' => [
'timeout' => 30,
'debug' => true, // Enable debug logs
],
Database Conflicts:
created_at, ensure the bundle’s entity doesn’t override it. Solution: Extend the entity and add:
use Illuminate\Database\Eloquent\Concerns\HasTimestamps;
Custom Response Processing:
ApiHistogram\ApiHistogramBundle\Service\ApiHistogramService to transform responses before storage:
// app/Services/CustomApiHistogramService.php
public function processResponse($response, $target) {
$data = json_decode($response->getBody(), true);
return collect($data)->only(['relevant', 'fields']);
}
Webhook Triggers:
// app/Providers/EventServiceProvider.php
protected $listen = [
'api.requested' => [CustomApiLogger::class, 'logResponse'],
];
Multi-Tenant Support:
tenant_id field to the histogram table and scope queries:
// ApiHistogramBundle/Entity/ApiHistogram.php
public function scopeForTenant($query, $tenantId) {
return $query->where('tenant_id', $tenantId);
}
How can I help you explore Laravel packages today?