🔍 SearchPackages
Searches packages on Packagist by keyword, with pagination.
When to use
🔍 Find packages by keyword in a package picker / IDE plugin; 📊 compare download counts and favorites across candidate packages; 🧭 perform a fuzzy lookup when the user types free-form text.
Signature
go
func (c *ComposerClient) SearchPackages(query string, perPage, page int) (*domain.SearchResponse, error)Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | Search keyword, e.g. http client |
perPage | int | Results per page; pass 0 or negative to omit the per_page parameter (uses the endpoint default) |
page | int | Page number; pass 0 or negative to omit the page parameter |
Return value
| Value | Type | Description |
|---|---|---|
| Result | *domain.SearchResponse | Results is []SearchResult (with name/description/url/repository/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/search.json?q={query}.
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.SearchPackages("http client", 15, 1)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total results: %d\n", resp.Total)
for i, r := range resp.Results {
fmt.Printf("%2d. %s (downloads %d, favorites %d)\n", i+1, r.Name, r.Downloads, r.Favers)
}
}Advanced
- 🏷️ To search by tags, use
SearchPackagesByTags. - 🧩 To search by type + keyword, use
SearchPackagesByType. - 📦 Once you have a package name, fetch the full details with
GetPackage.