4

I need to append query params to endpoint URI according to query params in request.

I have an resource API in ESB published like this:

<resource methods="GET" url-mapping="/searchEngine/sortAndFilterVolunteers*">
  <inSequence>
     <send>
        <endpoint>
           <address
                uri="http://localhost:8080/project-web-services/services/project-rs"></address>
        </endpoint>
     </send>
  </inSequence>

I have to append query params dinamically.

How could I do that?

Community
  • 1
  • 1
Sergio Rodríguez Calvo
  • 1,183
  • 2
  • 16
  • 32

3 Answers3

2

Following sample API definition may help you.

<api xmlns="http://ws.apache.org/ns/synapse" name="sample" context="/api/sample">
   <resource methods="OPTIONS GET" uri-template="/{val1}/groups/{val2}.json?q1={v1}&q2={v2}">
  <inSequence>
     <property name="uri.var.q1" expression="$url:q1"></property>
     <property name="uri.var.q2" expression="$url:q2"></property>
     <property name="uri.var.val1" expression="get-property('uri.var.val1')"></property>
     <property name="uri.var.val2" expression="get-property('uri.var.val2')"></property>
     <send>
        <endpoint>
           <http method="GET" uri-template=""></http>
        </endpoint>
     </send>
  </inSequence>
  <outSequence>
     <send></send>
  </outSequence>
  </resource>
</api>
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
  • My problem is that the URL is different each time. For example, a request may be http://server:port/service?q1={q1} and other request may be http://server:port/service?q2={q2}&q3={q3}. This is because they are optional, and need to do the mapping according to those arriving params with the request. – Sergio Rodríguez Calvo Jun 08 '15 at 08:46
0

Add the query parameter to uri-template in resource as below :

<resource methods="GET" uri-template="/getStudents/{id}">

When sending to the endpoint,

<send>
    <endpoint>
        <http method="get" uri-template="http://studentsapi/student/{uri.var.id}"/>
    </endpoint>
</send>
maheeka
  • 1,983
  • 1
  • 17
  • 25
0

Add the query parameter to url-mapping in resource as below : url-mapping="/*"

*

you can send a request may be server:port/service?q1={q1} and other request may be server:port/service?q2={q2}&q3={q3}.