Skip to content

Commit b24e8f4

Browse files
Merge pull request #138 from packagist/update-docs-paging-api
Docs: add API pagination guide
2 parents c37f867 + afe7a75 commit b24e8f4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

docs/api/api-pagination.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# API Pagination
2+
##
3+
4+
All Private Packagist API endpoints that return lists support pagination using query parameters. This allows you to efficiently retrieve large result sets by fetching data in smaller chunks.
5+
6+
> **✨ Automatic Pagination**: If you're using the [PHP API client](https://github.com/packagist/private-packagist-api-client), pagination is handled automatically! The client fetches all pages transparently and returns complete results. You don't need to manually handle pagination, Link headers, or page loops - just call the endpoint method and get all results.
7+
8+
If you were previously using list endpoints without pagination: Your existing code will continue to work, but the hard limit is set to 10,000 items, which covers most use cases.
9+
10+
## Query Parameters
11+
12+
Paginated list endpoints (all that do get a collection of items) accept the following query parameters:
13+
14+
* `page` (integer, optional): Page number to retrieve (1-10,000). Default: 1
15+
* `limit` (integer, optional): Number of items per page (1-10,000). Default: 10,000
16+
17+
### Example Request
18+
19+
```bash
20+
GET /api/packages/?page=2&limit=300
21+
```
22+
23+
This fetches the second page of packages with 300 packages per page.
24+
25+
## Response Format
26+
27+
### Link Header
28+
29+
Paginated responses include an [RFC 5988](https://tools.ietf.org/html/rfc5988) Link header containing pagination navigation URLs:
30+
31+
```
32+
Link: <https://packagist.com/api/packages/?page=3&limit=300>; rel="next",
33+
<https://packagist.com/api/packages/?page=1&limit=300>; rel="prev",
34+
<https://packagist.com/api/packages/?page=1&limit=300>; rel="first",
35+
<https://packagist.com/api/packages/?page=10&limit=300>; rel="last"
36+
```
37+
38+
The Link header includes up to four relations:
39+
40+
* `next`: URL to the next page (if available)
41+
* `prev`: URL to the previous page (if available)
42+
* `first`: URL to the first page
43+
* `last`: URL to the last page
44+
45+
### Response Body
46+
47+
The response body contains a JSON array of resources, just like non-paginated responses:
48+
49+
```json
50+
[
51+
{
52+
"id": 1,
53+
"name": "acme/package",
54+
...
55+
},
56+
...
57+
]
58+
```

0 commit comments

Comments
 (0)