API Documentation

Pkgsite provides a JSON API for accessing information about Go packages and modules.

Requests

All requests are GET requests whose first URL segment selects the request type. Except for search, the remaining segments specify a module or package path. Additional arguments are specified as query parameters.

Package paths are ambiguous: the same path a/b/c could be package c in module a/b or package b/c in module a. If both exist, the API returns an error with a list of possible modules in its candidates field. Make a follow-up request with the module query parameter to disambiguate. (Note: this behavior differs from the pkgsite UI, which selects the longest matching module path.)

Some routes accept an optional version query parameter. If missing, the latest version is chosen.

Some routes accept optional GOOS and GOARCH query parameters to select the desired build context of the documentation. If omitted, the default documentation build context is selected, typically linux/amd64.

Some routes accept a filter. Only items that match the filter are returned. The filter must be a Go expression that returns a boolean value. Filters support the following subset of Go:

In addition, each route adds its own variables for the list items being filtered. In general, each JSON field is a variable.

Most filters will need to be percent-encoded. Go programs should call url.QueryEscape to encode filters and all other query parameter values. Or better, put all values into a url.Values and then call Encode on that.

Responses

All routes return a JSON response. You can find a link to the corresponding Go type for a route in the documentation below. Errors are also returned as a JSON object, whose message field contains the error message.

You can access the machine-readable OpenAPI Specification.

Pagination

Some responses are paginated. Each response page has a nextPageToken, which is non-empty if there is another page of items. To retrieve the next page, repeat the original request verbatim, adding a token query parameter whose value is the next-page token from the response. Changing the request in any way other than providing a token may result in an error.

As long as nextPageToken is non-empty, there is another page, even if the current page has no items.

Routes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL