Sorting
Controlling result order with the sort_by parameter in the Ping Proxies API
The Ping Proxies API provides sorting capabilities that allow you to control the order of returned results. Proper sorting is essential for creating intuitive, user-friendly interfaces and for optimizing data processing workflows.
The sort_by
Parameter
All search endpoints in the Ping Proxies API support the sort_by
parameter, which allows you to specify fields to sort by and the direction of the sort.
Basic Sorting
The simplest form of sorting uses a single field name without any suffix, which sorts in ascending order (A-Z, oldest to newest):
This sorts results by the creation datetime in ascending order (oldest to newest).
Sort Direction
You can specify the sort direction by adding a direction suffix:
- Ascending: Add
_asc
suffix (default when no suffix is specified) - Descending: Add
_desc
suffix
This sorts services by expiry date in descending order (expiring soonest first).
This sorts proxies by country ID in ascending order (A-Z).
Special Sorting Options
Random Sorting
Some endpoints support a special random
sort option:
This returns results in a random order, which can be useful for:
- Load balancing across multiple proxies
- Selecting random samples for testing
- Presenting different options to users
Random sorting should not be used with pagination if you need to access the complete randomly ordered set, as each page will have its own random order.
Sorting and Pagination
Sorting works in conjunction with pagination. When you specify both a sort order and pagination parameters, the API:
- Applies the sort to the entire result set
- Divides the sorted results into pages
- Returns the requested page
For example:
This returns the second page of proxies, with 25 proxies per page, sorted by creation date from newest to oldest.
Code Examples
Examples for Common Use Cases
Show newest items first
Alphabetical order by name
Find proxies expiring soon (earliest first)
By effectively using the sorting capabilities of the Ping Proxies API, you can create more intuitive and efficient applications that present data in the most useful order for your specific needs.