Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Api filtering

 
Dhaval J. Patel
Ranch Hand
Posts: 90
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should you consider a new API with POST request for such parameters ?

Just a thought....
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dhaval, have you decided how to design api for filtering?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic