LazyCoder
LazyCoder

Reputation: 357

How do I use OR condition in payload of POST request?

I am using Python-Eve REST API and I want to read using POST. I want to use OR condition in my query payload like :

{"id":1 or "id":2}.

So that I will get all response with id = 1 or those with id = 2.

I am using SQLALCHEMY as my database.

Upvotes: 1

Views: 1268

Answers (3)

OneCricketeer
OneCricketeer

Reputation: 191748

Assuming you are using a Mongo Backend, look at the Mongo Query documentation

You can try a GET request to query values

http://app/values?where={ id: { $in: [1, 2] } }

Upvotes: 0

user8060120
user8060120

Reputation:

you can use $in in where clause in get request:

?where={"id":{"$in":["1", "2"]}}

Upvotes: 0

Vamsidhar Muggulla
Vamsidhar Muggulla

Reputation: 632

Simply use list as a value of that key, it makes easy for you with python lists.

payload = { "id": [1, 2] ... }

If the case if that any of the 'id' is zero or NoneType, you can use this condition.

variable_1 = None
variable_1 = 3

payload = {
  "id": variable_1 or variable2
}

#payload becomes like this 

payload = {
  "id": 3
} 

Upvotes: 2

Related Questions