0
votes

I am using wso2 API manager 3.2 and in my API there are some headers and Query Parameter.

My API has some path variable in URL in this way

http://example.com/data/readsomeData/{entityId}/{someId}

for the path variable I use the following mediator

    <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>

and it works fine.

also I change some of incoming header's name . For example incoming header is IN_HEADER , I translate it to OUT_HEADER ,my backend expects OUT_HEADER.

I also use this mediator

<property name="IN_HEADER" expression="get-property('transport', 'IN_HEADER')"/>
<property name="OUT_HEADER" expression="get-property('IN_HEADER')" scope="transport"/>
<property name="IN_HEADER" scope="transport" action="remove"/>

It also works fine too.

The given API describe above also has some optional query parameters (limit, max, min) . For example if I use limit=10 in my API, I have to get 10 records, with out limit I get just one record. In WSO2 API Manager Publisher I defined the above query parameters as the other parameters.

The problem is when I use each of query parameter I get the result same as the way I do not use the query parameters. I get only one record.

I think the API manager does not pass the query parameters to backend.

I don't know this problem related to the mediator I use or not!

1
I forgot to mention, I have three query parameters and all of them are optional something like this example.com/data/readsomeData{entityId}/{someId}?limit=XX&from=YY&to=ZZ here wso2.com/blogs/cloud/move-query-parameters-to-rest-path describes not optional parameters. @PubciMehdi Alisoltani
I tested the example.com/data/readsomeData{entityId}/{someId}?* but it doesn't work. @PubciMehdi Alisoltani

1 Answers

0
votes

You can approach this in a few different ways, below examples should also work on 3.2.0. Because you remove the REST_URL_POSTFIX the APIM also removes the query parameters. So option 1:

You could do something similar to what you did for the other headers. Grab the query parameters and add them as headers for further use. (the $url shorthand should also be available in 3.2.0 as far as I know - it grabs a query parameter by name.)

<property name="limit" expression="$url:limit" scope="transport"/>
<property name="min" expression="$url:min" scope="transport"/>
<property name="max" expression="$url:max" scope="transport"/> 

Or you could grab the query parameters from your URL and put them back after removing the POSTFIX.

<property name="newUrlPostfix" expression="substring after($axis2:REST_URL_POSTFIX, '?')"/> 
<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
<property name="REST_URL_POSTFIX" scope="axis2" expression="concat('?', $ctx:newUrlPostfix"/>