Sean Sun
Sean Sun

Reputation: 546

WSO2 ESB REST with dynamic parameters

I build up a API which should take dynamic parameters like below,

<api xmlns="http://ws.apache.org/ns/synapse" name="MrlDatabaseAPI" context="/rest">
     <resource methods="OPTIONS GET" uri-template="/reportNotes?country={country}&amp;pesticide={pesticide}&amp;crop={crop}">
  <inSequence>
     <send>
        <endpoint>
           <http method="GET" uri-template="http://172.17.100.113/MRLService/rest/v1/reportNotes?country={uri.var.country}&amp;pesticide={uri.var.pesticide}&amp;crop={uri.var.crop}"/>
        </endpoint>
     </send>
  </inSequence>

Now the resource only work if passing all three parameters, http://localhost/rest/reportNotes?country=AUS&pesticide=ABA3000&crop=22020100.

How can I tweak the API and make it accept any two parameters, like: http://localhost/rest/reportNotes?country=AUS&pesticide=ABA3000 or http://localhost/rest/reportNotes?country=AUS&crop=22020100

The Restful web service itself can accept any number of parameters.

Thanks, Sean

Upvotes: 0

Views: 399

Answers (1)

Dilshani Subasinghe
Dilshani Subasinghe

Reputation: 1952

According to your configuration, it can't be solve with any number of parameters.

You may solve the issue with "filter" mediator

Ex:

<filter source="boolean(get-property('uri.var.pesticide'))" regex="false">
  <then>
     <send>
    <endpoint>
       <http method="GET" uri-template="http://172.17.100.113/MRLService/rest/v1/reportNotes?country={uri.var.country}&amp;crop={uri.var.crop}"/>
    </endpoint>
 </send>
  </then>
  <else>
      <drop/>
  </else>
</filter>

You may implement your scenario with this mediator.

Upvotes: 1

Related Questions