Search code examples
modelloopbackjsstrongloop

How to Read Query Filters from Within a LoopBack Model


We're using LoopBack for our REST APIs and need to access the query filter (that was specified in the client) from within custom logic in the LoopBack model. For example, given this query:

http://localhost:1337/api/Menus/formatted?filter[where][id]=42

how would we access the 'where' parameter from within the 'Menu.formatted' code:

function asMenu(Menu) {
    Menu.formatted = function (callback) {

        <<Need to access the query filter here...>>

Solution

  • Declare filter query paramerter as argument for your formatted remote method and then access it just like callback argument.

    See how to describe arguments in docs.