0

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!

Mehdi Alisoltani
  • 349
  • 3
  • 13
  • Does this work for you ? https://wso2.com/blogs/cloud/move-query-parameters-to-rest-path/ – Pubci May 08 '21 at 03:19
  • I forgot to mention, I have three query parameters and all of them are optional something like this http://example.com/data/readsomeData/{entityId}/{someId}?limit=XX&from=YY&to=ZZ here https://wso2.com/blogs/cloud/move-query-parameters-to-rest-path/ describes not optional parameters. @Pubci – Mehdi Alisoltani May 08 '21 at 07:49
  • I tested the http://example.com/data/readsomeData/{entityId}/{someId}?* but it doesn't work. @Pubci – Mehdi Alisoltani May 10 '21 at 15:09

1 Answers1

0

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"/>
Novren
  • 69
  • 6
  • Is it possible to say how to define endpoint URL for assigning the parameters comes from the client to the endpoint? Assume I get the query parameter limit form the URL an put it in limit like this now how to pass in URL to backend ? @Novren – Mehdi Alisoltani May 14 '21 at 07:50
  • This issue becomes very time-consuming to me. There is not enough documentation even on wso2 api manager Documentation. – Mehdi Alisoltani May 14 '21 at 12:46
  • Transport scope properties should automatically show up as HTTP headers so they will be passed to the backend and should be visible there. Generally this mediation part of API manager is a lite version of what Enterprise integrator can do so if you're looking for more docus maybe you can find what you need in there. – Novren May 17 '21 at 06:36