RESTful URL design – how to query using OR between parameters

rest

How would you design a RESTful query to support OR operand between parameters.
Let's say my resource has two fields field1 & field2. How would you design the URL to enable the following query:

"Get myresources where field1=x OR field2=y"

Designing queries in REST is pretty straight forward, but I have only seen queries that supports AND between query fields. e.g. /myresource?field1=x&field2=y

A possible solution can be to provide a single query parameter with free text where part, for example:

GET /myresource?q={field1=x OR field2=y}

But that would make it more complicated for clients to parse and extend or reduce filtered fields.

What do you suggest?

Best Answer

Query params aren't by definition AND related, they're just inert params - how you handle them is up to you. For an OR search I'd suggest:

GET /myresources?field1=x&field2=y&inclusive=true

If you want to default to an AND relationship (reasonable), and any other extension you want is of course possible.

Related Topic