5

Can I include multiple "where" clauses (or an AND operator) in an endpoint query string? I'd like to do something like this:

http://localhost:5000/regions?where=name=="El Salvador"&where=lang=="es"

I've tried few different syntaxes, but I can't get it to work.

Is this possible? I know I can do it using MongoDB syntax, but I would like to use Python syntax.

Note: I'm not trying to concatenate an list of parameteres using python, I'm trying to use Eve's filtering feature using native python syntax.

8
  • not sure what you are asking. Is this what you are looking for? http://localhost:5000/regions?name="El Salvador"&lang="es" This will allow you to filter on the endpoint using those 2 query string arguments.
    – limbo
    Jun 29, 2016 at 23:50
  • @limbo I think it's not a duplicated question, I'm talking about Eve's syntax for filtering results through query string parameters.
    – PachinSV
    Jun 29, 2016 at 23:57
  • @limbo have you used Eve ?
    – PachinSV
    Jun 30, 2016 at 0:05
  • my bad, didn't use it, I should have looked into it a bit more. Guess I wasted a flag.
    – limbo
    Jun 30, 2016 at 0:12
  • @limbo this I wha't I'm trying to do but with 2 "where clauses" or an "AND" python-eve.org/features.html#filtering, look at "native python syntax"
    – PachinSV
    Jun 30, 2016 at 0:18

2 Answers 2

6

Have you tried http://localhost:5000/regions?where=name=="El Salvador"%20and%20lang=="es"?

You can replace %20 for space in the URL if it doesn't work. In my postman environment works both ways.

Seems to work like the AND you want. The documentation mentions it, but it misses an example I think. Mind the correct position for double quotes.

EDIT:

For boolean values, to filter _deleted is False, for example, the query format would be http://localhost:5000/regions?where=name=="El Salvador" and not _deleted

4
  • Yes, using MongoDB syntax works fine, I'm trying to do it using python syntax :)
    – PachinSV
    Jun 30, 2016 at 1:03
  • @PachinSV I have updated the answer to use python syntax.
    – gcw
    Jun 30, 2016 at 1:24
  • It worked using spaces localhost:5000/regions?where=name=="El Salvador" and lang=="en", you could update your answer to clarify that (you can use spaces or the html entity for a space %20)
    – PachinSV
    Jun 30, 2016 at 3:18
  • 1
    Sure @PachinSV , just did that.
    – gcw
    Jun 30, 2016 at 9:45
1

Querystring Array Parameters in Python using Requests
Looks like what you are after. The where clause is not necessary if you are using the '&' syntax so your clause should look something like this

http://localhost:5000/regions?name=='El Salvador'&lang=='es'
2
  • I test it, but it doesn't work.... in a matter of fact it does not apply any of the filters :(
    – PachinSV
    Jun 29, 2016 at 23:53
  • are you using the python requests library like in the link I posted?
    – Ali
    Jun 29, 2016 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.