Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is passing a query string parameter (whose value is null) without the equals sign valid?

Variation 1:

 file.jsp?parameter1=&parameter2=abc

Variation 2:

 file.jsp?parameter1&parameter2=abc

I know Variation 1 is considered valid, but is variation 2 considered valid? Specifically, there is no value for the parameter, is the equals sign required in this case?

like image 699
ehed Avatar asked Jan 22 '14 18:01

ehed


People also ask

Can query params be null?

null should be/can be represented by not sending the param. It just depends on how you build your API.

Is it permissible to pass a null value to this function?

It is absolutely fine to pass null to methods.

Does a query parameter need a value?

Yes, it is valid. If one simply want to check if the parameter exists or not, this is one way to do so.

Can we pass in query string?

To pass in parameter values, simply append them to the query string at the end of the base URL.


1 Answers

I think it is valid to have query parameter with just the parameter name.

If you are familiar with Java, Look at the @see UriComponentsBuilder QueryParam function, by default it does this for any query parameter with null.

If no values are given, the resulting URI will contain the query parameter name only (i.e. ?foo instead of ?foo=bar.

See this answer for more info. Is a url query parameter valid if it has no value?

like image 172
Maximus Avatar answered Oct 03 '22 19:10

Maximus