Search code examples
ibm-cloudstrongloopapiconnect

How to add a where filter to a path in IBM API Connect designer


I am using IBM API Connect designer and I want to add a filter to one of my paths. Specifically, I have the following API endpoint path:

http://127.0.0.1:4001/api/testusers

It relates to a table in my mySQL database.

I already have the full API built, but want to allow the API consumer to do a simple restful search: i.e.

http://127.0.0.1:4001/api/testusers?userName=Martin

However, I can't work out how to do it. I have looked over the documentation: http://www.ibm.com/support/knowledgecenter/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/task_apionprem_configure_operation.html

I have tried to log a question on their impossible set of forums, which has crashed each time.

I think it must be pretty straight forward to add from within the designer. However, I can't work it out or perhaps I have added it and can't work out the right path to use. But, either way, it doesn't work. Any direction is most appreciated.

The designer setup is given here: enter image description here

enter image description here


Solution

  • There are a couple of options available.

    Since you talk about connectivity to a database, I'm going to assume that you are using the Designer's model and datasource features as well (feel free to correct if I'm misunderstanding).

    These components are provided by the LoopBack framework. So, without doing any custom coding, you should be able to add a filter clause to your API call as a query param in the format filter[where][property]=value.

    So, in your case, it might look like: http://127.0.0.1:4001/api/testusers?filter[where][userName]=Martin

    More detail here: http://loopback.io/doc/en/lb2/Where-filter.html

    If you wanted to make it look more like your example, then you would need to write custom code in your underlying model. It's not difficult, but does have some learning curve. There's plenty of docs on that here: http://loopback.io/doc/en/lb2/Remote-methods.html and http://loopback.io/doc/en/lb2/Creating-models.html