nucleos/lastfm
PHP wrapper for the Last.fm API. Install via Composer and use PSR-18/PSR-17 clients (e.g., Symfony HttpClient + Nyholm PSR-7) to authenticate, create sessions, and query services like charts and top tags.
AuthService, ChartService) for different Last.fm API endpoints. This aligns well with Laravel’s modularity and service container, enabling clean separation of concerns.Illuminate\Http\Client) or third-party clients like Symfony’s HttpClient.album.getBuylinks, track.ban), which may require fallback strategies (e.g., web crawling or direct API calls) for legacy features.HttpClient (PSR-18 compliant) can replace symfony/http-client with minimal changes.config/services.php.Illuminate\Support\Facades\Auth or a custom guard could manage session tokens.App\Exceptions\Handler) can supplement this.Nucleos\LastFm\Crawler) or direct API calls be implemented?symfony/http-client with Laravel’s HttpClient for consistency:
$httpClient = new \Illuminate\Http\Client\PendingRequest();
$connection = new PsrClientConnection($httpClient, new Nyholm\Psr7\Factory\Psr17Factory());
AppServiceProvider:
$this->app->singleton(PsrClientConnection::class, fn($app) => new PsrClientConnection(
$app->make(\Illuminate\Http\Client\PendingRequest::class),
new Nyholm\Psr7\Factory\Psr17Factory()
));
.env:
LASTFM_API_KEY=your_api_key
LASTFM_TOKEN=your_oauth_token
$tags = Cache::remember('lastfm_top_tags', now()->addHours(1), fn() => $chartApi->getTopTags(10));
ScrobbleJob::dispatch($trackData)->onQueue('lastfm');
symfony/http-client with Laravel’s HttpClient..env.ChartService, AuthService) with caching.Auth::events()).nyholm/psr7 is lightweight and widely used; no major conflicts expected.symfony/http-client and Laravel’s HttpClient in the same project..env with Last.fm credentials.PsrClientConnection binding.composer.json scripts or GitHub Actions to auto-update dependencies.catch (LastFmException $e) {
report($e);
return response()->json(['error' => 'Last.fm API error'], 500);
}
tap() or dump() for debugging API responses:
$tags->tap(fn($data) => \Log::debug('Top tags:', $data));
.env:
HTTP_CLIENT_LOG=true
HttpClient supports this).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Last.fm API downtime | Feature unavailability | Implement fallback to cached data or user notifications. |
| Rate limit exceeded | Throttled requests | Queue requests, use caching, and implement exponential backoff. |
| Invalid API token | Authentication failures | Add middleware to validate tokens on each request. |
| Malformed API response | Application crashes | Add response validation (e.g., JSON schema checks) or graceful fallbacks. |
| Dependency version |
How can I help you explore Laravel packages today?