I have a design question for filtering for rest api. I am new to using rest api and I would love to hear opinions from all the experienced folks.
So the api we have allows users to get info on different entities that we have in our databases. These are simple get requests. We also allow consumers to pass filter parameters for eg. /abc?a=1&b=2 etc. and the results would be filtered based on what is being passed. Now the new requirement is to provide users with possible filtering options. So that query would return possible filtering values for all the fields in an entity. Like possible values for field 'a' is 1,2 and 3, for b is 2,4,5 etc.
We could do labour work there and write code to find out distinct values from the database and write code that gets possible filtering values for each field. But then thats hard to maintain. Every time we add a field we need to update the filtering code as well as the metadata code.
If we decide to write a framework to do the entire filtering, the issue is that those fields could be different datatypes. So we couldnt really just fetch distinct values from the database.
We use jersey and ibatis for orm.
I was wondering if anyone has run into similar problem and thought of a clean solution for it.