Have you checked the following policy snippets?
https://github.com/Azure/api-management-policy-snippets/blob/master/policy-expressions/README.md
These snippets might be helpful for you. If you can retrieve values from query/path parameters, you can construct a URLs with path/query parameters to align with backend service. Here are samples.
[Base URL]
APIM (API Service): https://<instance>.azure-api.net/api
Backend Service: https://<BackendService_URL>/api
[1] Query paramter to path parameter
https://<instance>.azure-api.net/api/path/{param}
-> https://<BackendService_URL>/api/query?q={param}
<inbound>
<base />
<rewrite-uri id="setPathParam" template="@{
return "/query?q="+context.Request.MatchedParameters.GetValueOrDefault("param","notfound");
}" />
</inbound>
[2] Path parameter to query parameter
https://<instance>.azure-api.net/api/query?q={param}
-> https://<BackendService_URL>/api/path/{param}
<inbound>
<base />
<rewrite-uri id="setQueryParam" template="@{
return "/path/"+context.Request.Url.Query.GetValueOrDefault("q", "notfound");
}" />
</inbound>