Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Filter model data in LoopBack

    Bram BorggreveBram Borggreve

    In this lesson we will look at the filters that can be used to retrieve and manipulate the data stored in LoopBack.

    We will use Postman to interact with the /Categories and /Products endpoints.

    Using the URL parameters we will apply at the various filters LoopBack has to offer: include, order, where, fields, limit and offset.

    loopbackLoopback
    nodeNode.js
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 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.

    00:14 We can apply the filters using URL parameters. For example, with the include filter, we can include the products that belong in a category.

    00:24 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.

    00:43 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.

    01:03 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.

    Discuss

    Discuss