Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OR statement in URL query string

I need to support OR statement in REST API, and I don't know how to build right query string. Maybe, something like this?

  • /rest?author=Obama&author=McCain
  • /rest?author=Obama|McCain

or maybe standard solution exists?

like image 503
Denis Sokolov Avatar asked Oct 11 '13 11:10

Denis Sokolov


People also ask

What is %20 in query string?

According to the W3C (and they are the official source on these things), a space character in the query string (and in the query string only) may be encoded as either " %20 " or " + ".

What is Querystring in URL?

On the internet, a Query string is the part of a link (otherwise known as a hyperlink or a uniform resource locator, URL for short) which assigns values to specified attributes (known as keys or parameters). Typical link containing a query string is as follows: http://example.com/over/there?

How can I pass two parameters in URL?

To add a parameter to the URL, add a /#/? to the end, followed by the parameter name, an equal sign (=), and the value of the parameter. You can add multiple parameters by including an ampersand (&) between each one.

What is %27 in query string?

The %27 is ASCII for the single quote ( ' ) and that is a red flag for someone trying to perform SQL injection via the query string to your application's data access layer logic.


1 Answers

Option 1: You can have a string that represents all of the values. and in code, you'll break the string apart according to some delimiter.

key=val1,val2,val3

and lets say (in pseudo code): var vals = explode( GETPARAMS['key'] , ',' )

Option 2: You can use array notation in your url arguments:

key[0]=val1&key[1]=val2&key[2]=val3

and in code, the value of key will be an array: array( val1, val2, val3 )

like image 108
Kristian Avatar answered Oct 11 '22 13:10

Kristian