File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Api filtering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Api filtering" Watch "Api filtering" New topic

Api filtering

Dhaval J. Patel
Ranch Hand

Joined: Mar 10, 2011
Posts: 90

Hi all,

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.

surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

Hey, maybe Apache Lucene is all you need. You have entities stored in DB, and you need different search options to fetch right entities from DB.
Thillai Sakthi
Ranch Hand

Joined: Jun 17, 2000
Posts: 103
Should you consider a new API with POST request for such parameters ?

Just a thought....

surlac surlacovich
Ranch Hand

Joined: Mar 12, 2013
Posts: 296

Dhaval, have you decided how to design api for filtering?
I agree. Here's the link:
subject: Api filtering
It's not a secret anymore!