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.

Luke Taylor
  • 8,631
  • 8
  • 54
  • 92
PachinSV
  • 3,680
  • 2
  • 29
  • 41
  • 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 '16 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 '16 at 23:57
  • @limbo have you used Eve ? – PachinSV Jun 30 '16 at 00:05
  • my bad, didn't use it, I should have looked into it a bit more. Guess I wasted a flag. – limbo Jun 30 '16 at 00:12
  • @limbo this I wha't I'm trying to do but with 2 "where clauses" or an "AND" http://python-eve.org/features.html#filtering, look at "native python syntax" – PachinSV Jun 30 '16 at 00:18
  • I see now, what do you get with your current syntax, do you get the first filter working? Does it just ignore the part after the and? – limbo Jun 30 '16 at 00:42
  • can you try using `http://localhost:5000/regions?where=name=="El Salvador"&lang=="es"` – limbo Jun 30 '16 at 00:42
  • Thanks @limbo I tried that URL but the seconde parameter (and) is ignored, I get all results for name=="El Salvador" but with all the languages available (en, es, pt) – PachinSV Jun 30 '16 at 00:45

2 Answers2

5

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.

gcw
  • 1,639
  • 1
  • 18
  • 37
  • Yes, using MongoDB syntax works fine, I'm trying to do it using python syntax :) – PachinSV Jun 30 '16 at 01:03
  • @PachinSV I have updated the answer to use python syntax. – gcw Jun 30 '16 at 01:24
  • It worked using spaces http://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 '16 at 03:18
  • 1
    Sure @PachinSV , just did that. – gcw Jun 30 '16 at 09: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'
Community
  • 1
  • 1
Ali
  • 633
  • 1
  • 9
  • 20