Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify rewrite url for query string parameters in Azure API Management

I'm using the Azure API Management to transform the incoming query string into another query string.

My transformation code is:

<policies>
    <inbound>
        <rewrite-uri template="api/primes?a={a}&b={b}" />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

When I try to save the edits, the error appears:

One or more fields contain incorrect values: 
'=' is an unexpected token. The expected token is ';'. Line 15, position 50.

which refers to the equals symbol as in a={a}. How do I correct the template of the rewrite-uri? The input url is for example https://example.com/sum?a=7&b=5.

like image 945
Phillip Ngan Avatar asked Jul 09 '18 21:07

Phillip Ngan


People also ask

How we can pass query parameter in URL?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.

What are query string parameters in URL?

What are query string parameters? Query string parameters are extensions of a website's base Uniform Resource Locator (URL) loaded by a web browser or client application. Originally query strings were used to record the content of an HTML form or web form on a given page.


1 Answers

Try replacing:

<rewrite-uri template="api/primes?a={a}&b={b}" />

With:

<rewrite-uri template="api/primes?a={a}&amp;b={b}" />

Find more details at https://azure.microsoft.com/en-us/blog/policy-expressions-in-azure-api-management/.

like image 111
Evandro de Paula Avatar answered Oct 23 '22 22:10

Evandro de Paula