loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.93k stars 1.06k forks source link

Loopback 4 Get Param Query #2468

Closed bijarniya closed 4 years ago

bijarniya commented 5 years ago

Hello Guys, My JSON query not working. I am trying to fetch data from loop4 - by using get Method My param like as -

{
"where": {"status":1},
"limit": 10,
"skip": 0
}

This thing is not working for me but I am trying in another way as

this.url + '?filter[where][status]=1&filter[offset]=0&filter[limit]=' + limit +
'&filter[skip]=' + skip + ''

this is working.

So please tell me how can I process my JSON params to make this type of query.

marioestradarosa commented 5 years ago

this works for me in the query path, I

account?filter={"where": { "customerNumber": "108809"}, "limit": 10, "offset": 1, "skip": 0}

Have you tried:

const whereClause = {
    where: { status : 1 },
    limit: 10, skip: 0, offset: 0
}
this.url + '?filter=' + JSON.stringify(whereClause);
bijarniya commented 5 years ago

@marioestradarosa This not working

const whereClause = {
    where: { status : 1 },
    limit: 10, skip: 0, offset: 0
}
this.url + '?filter=' + JSON.stringify(whereClause);

Required this format

this.url + '?filter[where][status]=1&filter[offset]=0&filter[limit]=' + limit +
'&filter[skip]=' + skip + '

How can we generate this?.

marioestradarosa commented 5 years ago

Have you tried only with the where and see if at least it is filtering ?

const whereClause = {
   where: { status: 1  }
};
this.url + '?filter=' + JSON.stringify(whereClause);

Loopbak uses qs https://github.com/ljharb/qs under the hood. so the format [foo]=bar is being parsed into a json object.

dhmlau commented 4 years ago

Closing due to inactivity.