🔥 ListPopularPackages
Fetches the list of popular Packagist packages (sorted by downloads / favorites).
When to use
🔥 Display a popular-packages leaderboard; 🎯 provide a reference for choosing packages in new projects; 📈 analyze the most active packages in the ecosystem.
Signature
go
func (c *ComposerClient) ListPopularPackages(perPage int) (*domain.PopularPackagesResponse, error)Parameters
| Parameter | Type | Description |
|---|---|---|
perPage | int | Number of results per page, e.g. 100 |
Return value
| Value | Type | Description |
|---|---|---|
| Result | *domain.PopularPackagesResponse | Packages is []PopularPackage (with name/description/url/downloads/favers), Total is the total count, Next is the URL of the next page |
| Error | error | Returned on HTTP failure, non-200 status, or JSON parse failure |
Corresponding endpoint: GET https://packagist.org/explore/popular.json?per_page={perPage}.
Example
go
package main
import (
"fmt"
"log"
"time"
"github.com/scagogogo/composer-skills/pkg/client"
)
func main() {
c := client.NewComposerClient(30 * time.Second)
resp, err := c.ListPopularPackages(20)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total: %d\n", resp.Total)
for i, p := range resp.Packages {
fmt.Printf("%2d. %s (downloads %d, favorites %d)\n", i+1, p.Name, p.Downloads, p.Favers)
}
if resp.Next != "" {
fmt.Println("Next page:", resp.Next)
}
}Advanced
- 📈 For repository-wide totals, use
GetStatistics. - 🔍 To search by keyword, use
SearchPackages. - 📦 For the full metadata of a given package, use
GetPackage.