Skip to content

🔍 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

ParameterTypeDescription
querystringSearch keyword, e.g. http client
perPageintResults per page; pass 0 or negative to omit the per_page parameter (uses the endpoint default)
pageintPage number; pass 0 or negative to omit the page parameter

Return value

ValueTypeDescription
Result*domain.SearchResponseResults is []SearchResult (with name/description/url/repository/downloads/favers), Total is the total count, Next is the URL of the next page
ErrorerrorReturned 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

Released under the MIT License