Searching and sorting

APIs usually support searching so that a subset of the collection is returned. For example, the following is a request to get only completed orders:

https://api.examplebucks.org/v1/orders?status=completed

As you can see, we put the status field as a query parameter to the URI. This is the preferred way of doing the search for a collection. You don't need to add /search to the URI, like in the following code:

https://api.examplebucks.org/v1/orders/search?status=completed // Avoid

And the following request will return all the completed orders, with the latest completed at the top of the list:

https://api.examplebucks.org/v1/orders?status=completed&sort=-completedDate

As you can see, we use the sort parameter to trigger the sorting. Prepending - is used for specifying a descending sort.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.168.203