Sanjay
Sanjay

Reputation: 63

Azure APIM policy to pass query param as a path param

Is there a way to pass the query param coming via the APIM request as path param to the backend service call? For example:

For the below API call

base_url/a/{pathParam1}?query=Qvalue

I want to transform the URL to:

base_url/a/Qvalue/{pathparam1}

Also I will be using the URL re-write policy to change the base_url and add newer query params.

Upvotes: 3

Views: 5695

Answers (1)

Pankaj More
Pankaj More

Reputation: 533

You can read the query parameter in policy expression with : context.Request.Url.Query.GetValueOrDefault("", "default value").

Asper the requirement, you need to change the uri, which can be set with rewrite-uri policy. So, your required policy statement should look like below (add in inbound section):

<rewrite-uri id="setQvalue" template="@{ 
                return "/base_url/a/Qvalue/"+context.Request.Url.Query.GetValueOrDefault("pathparam1", ""); 
            }" /> 

Upvotes: 4

Related Questions