Skip to content

Querystring behaviour is inconsistent when integrating other Loopback APIs #324

@horiaradu

Description

@horiaradu

Loopback has a particular interface for REST APIs. It allows you to write a query like so:

Model.find({where: {id: {inq: [1, 2, 3]}}})

However, this query is also valid: Model.find({where: {id: {inq: []}}}), but it will obviously not return any results.

In this case, the generated query looks like this:

http://localhost:3010/api/model?filter=%7B%22where%22%3A%20%7B%22id%22%3A%20%7B%22inq%22%3A%20%5B%5D%7D%7D%7D

and decoded, like this:

http://localhost:3010/api/model?filter={"where": {"id": {"inq": []}}}

The problem is inside http-invocation.js, line: 215.

// query is an object: query = {where: {id: {inq: []}}}
qs.stringify(query) //this will return an empty string

Querystring behaviour (from node REPL):

> qs.stringify({where: {id: {inq: [1]}}})
'where%5Bid%5D%5Binq%5D%5B0%5D=1'
> qs.stringify({where: {id: {inq: []}}})
''
>

If you are integrating another loopback API, when you do the query with an empty array, you expect to get back an empty collection of items, but instead, because of the behaviour of querystring, you get back all the items.

See related issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions