Is there any convention on how to use OR in url query parameters?

Viewed 21

I have the following URI:

mywebsite.com/api/records/?mode=timeline&ordering=-date_debut&page_size=50&date_debut=notnull&deadline=notnull

What I want is to change date_debut and deadline to be returned if any of them is notnull.

From:

date_debut=notnull&deadline=notnull

To something like:

date_debut=notnull||deadline=notnull

How I am able to do this?

1 Answers

When HTML forms build query strings, the parameters are ALWAYS delimited by &. When server side libraries parse query strings, they do so based on & delimiters. When you try to use || in a query string, your example will actually be parsed as a single name value pair named date_debut with a value of notnull||deadline=notnull.

That being said, if you are generating the query strings with your own code, and parsing them with your own code, you can do as you want. | is not a reserved character in URLs, so you could use it as in your example. You'd just have to write your own query string parser.

If you wanted to use the usual semantics of query strings I might suggest using an additional parameter that says what type of boolean operation to apply. Something like date_debut=notnull&combine=or&deadline=notnull.

Related