Reputation: 301
I need to support OR statement in REST API, and I don't know how to build right query string. Maybe, something like this?
or maybe standard solution exists?
Upvotes: 11
Views: 28489
Reputation: 21830
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 )
Upvotes: 2
Reputation: 11746
You could go for OpenData filter which allows complex filters.
Where the endpoint in your example would look like:
/rest?$filter=author eq Obama and author eq McCain
/rest?$filter=author eq Obame or author eq McCain
If you are using Asp.NET Web-Api you could use Microsoft ASP.NET Web API OData.
Disclamer: Using OData in Web-Api works using Entity Framework (or something that uses IQueryable)
Upvotes: 0