Skip to content

🧩 SearchPackagesByType

Searches packages on Packagist by keyword + package type, with pagination.

When to use

🧩 Search by keyword only within a specific type (e.g. composer-plugin); 🏗️ discover packages by combining type + functionality; 🎯 narrow the candidate set more precisely than a generic search.

Signature

go
func (c *ComposerClient) SearchPackagesByType(query, packageType string, perPage, page int) (*domain.SearchResponse, error)

Parameters

ParameterTypeDescription
querystringSearch keyword, e.g. installer
packageTypestringPackage type, e.g. composer-plugin, library
perPageintResults per page; pass 0 or negative to omit the per_page parameter
pageintPage number; pass 0 or negative to omit the page parameter

Return value

ValueTypeDescription
Result*domain.SearchResponseResults is []SearchResult, 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}&type={type}.

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.SearchPackagesByType("installer", "composer-plugin", 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%s\n", i+1, r.Name, r.Description)
	}
}

Advanced

Released under the MIT License