We can use filters to manipulate which data gets returned by loopback. Let's see this in action. We'll interact with the GetCategories and GetProducts endpoints. I used the API Explorer to create some sample data to play with.
We can apply the filters using URL parameters. For example, with the include filter, we can include the products that belong in a category.
Now, let's get to our products endpoints and we include the category in the result. We use the order filter to sort in price ascending or descending. We add a where filter to only return all products with a price higher than 200. Using the where filter, we can also do a wildcard search using like.
The filter field is used to only show certain fields. When filtering on fields, we see that our category is no longer included in the results. To fix our include filter, we need to make sure that we add our foreign key in the fields filter. Once we add category ID to our fields filter, we see that the category is included again.
Next, we add a limit filter to limit the number of items in our result. We can use the offset filter to skip items from the results. The last two filters can be useful if you want to page through the data.