Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Packagist Api

Packagist Api Laravel Package

knplabs/packagist-api

A simple object-oriented PHP wrapper for the Packagist API, offering package search, full package details, and efficient Composer metadata retrieval. Easily list results, limit pages, and access names, descriptions, and versions.

View on GitHub
Deep Wiki
Context7

Packagist API is a simple object-oriented PHP wrapper for the Packagist API, letting you search packages and retrieve package metadata without writing raw HTTP requests. Install it via Composer and use Packagist\Api\Client; it requires PHP ^8.0.

  • Package search with optional pagination.
  • Full package details via get(), including descriptions and metadata.
  • Efficient composer metadata via getComposer() using Packagist’s cached responses.
  • Object-oriented results for packages and versions with convenient getters.
  • Simple client API for quick integration into PHP applications.
Frequently asked questions about Packagist Api
How do I install knplabs/packagist-api in Laravel?
Install the package via Composer using the command composer require knplabs/packagist-api. It requires PHP 8.0 or higher. No Laravel service provider or facade is needed; you can instantiate the client directly in your code.
Is knplabs/packagist-api compatible with Laravel 10 or 11?
The package is framework-agnostic and only requires PHP ^8.0, so it works with any Laravel version that runs on PHP 8.0 or higher, including Laravel 10 and 11. There is no Laravel-specific integration to configure.
How do I search for packages using knplabs/packagist-api?
Create a new Packagist\Api\Client instance and call the search method with your query string. You can limit the number of pages returned by passing a page count as the third argument, for example $client->search('sylius', [], 2). The method returns an iterable collection of package objects.
Can I get composer metadata for a package with this package?
Yes, use the getComposer method to fetch Composer metadata, which is Packagist's preferred and more efficient way to retrieve package details. It returns an indexed array of packages, so you need to select the requested one by name. This response lacks some metadata provided by get() but benefits from efficient caching.
Does knplabs/packagist-api require authentication or API keys?
No, the Packagist API endpoints used by this package are public and do not require authentication or API keys. You can use the client out of the box without any credentials. However, be mindful of rate limits and consider caching responses.
How do I handle rate limiting with knplabs/packagist-api?
The package itself does not include rate limiting logic. You should implement caching or throttling in your Laravel application to avoid hitting Packagist's rate limits. Laravel's cache and HTTP client features can help you manage this.
Can I use knplabs/packagist-api in a Laravel service or controller?
Yes, you can instantiate the Packagist\Api\Client anywhere in your Laravel application, such as in controllers, services, or jobs. Since it is a plain PHP class, you can also bind it in Laravel's service container for dependency injection if you prefer.
How do I test code that uses knplabs/packagist-api?
You can mock the Client class or use Laravel's HTTP fake to simulate Packagist API responses in your tests. Since the package uses an HTTP client internally, you can inject a mock or create a fake implementation of the client. This allows you to test your application logic without making real API calls.
What are the alternatives to knplabs/packagist-api for Laravel?
Alternatives include using Packagist's official API directly with Laravel's HTTP client, or other PHP wrappers for Packagist. Some developers also use Composer's internal classes, but knplabs/packagist-api offers a simple object-oriented wrapper that is easy to integrate.
Is knplabs/packagist-api actively maintained?
Yes, the package is maintained by KnpLabs and has recent releases supporting PHP 8.0 and higher. The GitHub repository shows active build status and issue tracking. You can check the latest stable version on Packagist for updates.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager