I’m designing a RESTful API and I’m trying to work out how I could represent a predicate with OR an operator when querying for a resource.
For example if I had a resource Foo with a property Name, how would you search for all Foo resources with a name matching “Name1” OR “Name2”?
This is straight forward when it’s an AND operator as I could do the following:
http://www.website.com/Foo?Name=Name1&Age=19
The other approach I’ve seen is to post the search in the body.
You will need to pick your own approach, but I can name few that seem to be pretty logical (although not without disadvantages):
Option 1.: Using
|operator:Option 2.: Using modified query param to allow selection by one of the values from the set (list of possible comma-separated values):
Option 3.: Using PHP-like notation to provide list instead of single string:
All of the above mentioned options have one huge advantage: they do not interfere with other query params.
But as I mentioned, pick your own approach and be consistent about it across your API.