Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple "where clauses" in endpoint query string parameters

Tags:

python

eve

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.

like image 852
PachinSV Avatar asked Jun 29 '16 23:06

PachinSV


People also ask

How do you separate query parameters?

URL parameters are made of a key and a value, separated by an equal sign (=). Multiple parameters are each then separated by an ampersand (&).

What is QueryString in API?

A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters.

How do you pass query parameters in Python?

To send parameters in URL, write all parameter key:value pairs to a dictionary and send them as params argument to any of the GET, POST, PUT, HEAD, DELETE or OPTIONS request. then https://somewebsite.com/?param1=value1&param2=value2 would be our final url.

What is query string syntax?

QueryString. Query Strings are also generated by form submission or can be used by a user typing a query into the address bar of the browsers. Query Strings are contained in request headers. A Query String collection is a parsed version of the QUERY_STRING variable in the Server Variables collection.


2 Answers

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.

like image 167
gcw Avatar answered Nov 14 '22 22:11

gcw


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'
like image 40
Alastair Avatar answered Nov 14 '22 21:11

Alastair